Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-adapter into devel

# Conflicts:
#	History.md
#	gemfiles/ar42.gemfile
#	gemfiles/ar50.gemfile
#	lib/active_record/connection_adapters/mysql2rgeo/version.rb
#	lib/active_record/connection_adapters/postgis/schema_statements.rb
#	lib/active_record/connection_adapters/postgis/spatial_column.rb
#	lib/active_record/connection_adapters/postgis/spatial_table_definition.rb
#	lib/active_record/connection_adapters/postgis_adapter.rb
#	test/ddl_test.rb
#	test/tasks_test.rb
  • Loading branch information
jeff.yd(황용대) committed May 31, 2017
2 parents 7f6b753 + fdb2a10 commit 679bec4
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 110 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ dist: trusty
language: ruby
sudo: required
rvm:
- 2.4.0
- 2.3.3
- 2.2.6
- 2.4.1
- 2.3.4
- 2.2.7
- jruby-9.0.5.0
gemfile:
- gemfiles/ar50.gemfile
- gemfiles/ar51.gemfile
matrix:
allow_failures:
- rvm: jruby-9.0.5.0
Expand Down
4 changes: 2 additions & 2 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
appraise "ar50" do
gem "activerecord", "~> 5.0.0"
appraise "ar51" do
gem "activerecord", "~> 5.1.0"
end
11 changes: 4 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@ bundle install

Make sure the tests pass:

`rake`
`bundle exec rake`

Run tests against both ActiveRecord 4.0 and 4.1 test gemfiles:
Run tests against the test gemfiles:

run `rake appraisal` or run the tests manually:

```
BUNDLE_GEMFILE=./gemfiles/ar40.gemfile bundle
BUNDLE_GEMFILE=./gemfiles/ar40.gemfile rake
BUNDLE_GEMFILE=./gemfiles/ar41.gemfile bundle
BUNDLE_GEMFILE=./gemfiles/ar41.gemfile rake
BUNDLE_GEMFILE=./gemfiles/ar51.gemfile bundle
BUNDLE_GEMFILE=./gemfiles/ar51.gemfile rake
```

Make your changes and submit a pull request.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 2.0.1 / 2017-05-01

* Support ActiveRecord 5.1
* Fix activerecord gem dependency

### 1.0.0 / 2017-02-09

* Release
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ gem 'ffi-geos'

_JRuby support for Rails 4.0 and 4.1 was added in version 2.2.0_

#### Version 5.x supports ActiveRecord 5.1+

Requirements:

```
ActiveRecord 5.1+
Ruby 2.2.2+ (no JRuby support yet)
PostGIS 2.0+
```

#### Version 4.x supports ActiveRecord 5.0+

Requirements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 2.2.2"

spec.add_dependency "activerecord", "~> 5.0.0"
spec.add_dependency "rgeo-activerecord", "~> 5.0.0"
spec.add_dependency "activerecord", "~> 5.1"
spec.add_dependency "rgeo-activerecord", "~> 5.1"

spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "minitest", "~> 5.4"
Expand Down
12 changes: 0 additions & 12 deletions gemfiles/ar42.gemfile

This file was deleted.

12 changes: 0 additions & 12 deletions gemfiles/ar50.gemfile

This file was deleted.

11 changes: 11 additions & 0 deletions gemfiles/ar51.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "mysql2", "~> 0.4", platform: :ruby
gem "activerecord-jdbcmysql-adapter", '~> 1.3', platform: :jruby
gem "ffi-geos", platform: :jruby
gem "byebug", platform: :mri_23
gem "activerecord", "~> 5.1.0"

gemspec :path => "../"
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ def new_column(*args)
SpatialColumn.new(*args)
end

def type_to_sql(type, limit = nil, precision = nil, scale = nil, array = nil)
def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **) # :nodoc:
if (info = spatial_column_constructor(type.to_sym))
type = limit[:type] || type if limit.is_a?(::Hash)
type = "geometry" if type.to_s == "spatial"
type = 'geometry' if type.to_s.eql? 'spatial'
type = type.to_s.delete("_").upcase
end
super(type, limit, precision, scale, array)
super
end

def spatial_column_constructor(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,34 @@ def new_column_definition(name, type, options)
options.merge!(limit) if limit.is_a?(::Hash)
end

geo_type = ColumnDefinition.geo_type(options[:type] || type || info[:type])
geo_type = ColumnDefinitionUtils.geo_type(options[:type] || type || info[:type])
base_type = info[:type] || :geometry

# puts name.dup << " - " << type.to_s << " - " << options.to_s << " :: " << geo_type.to_s << " - " << base_type.to_s

options[:spatial_type] = geo_type
column = super(name, geo_type.downcase.to_sym, options)
column.spatial_type = geo_type
column.srid = options[:srid]
else
column = super(name, type, options)
end

column
end

private

def create_column_definition(name, type)
if Mysql2RgeoAdapter.spatial_column_options(type.to_sym)
Mysql2Rgeo::ColumnDefinition.new(name, type)
else
super
end
end
end

class ColumnDefinition < MySQL::ColumnDefinition
# needs to accept the spatial type? or figure out from limit ?

def self.geo_type(type = "GEOMETRY")
g_type = type.to_s.delete("_").upcase
return "POINT" if g_type == "POINT"
return "POLYGON" if g_type == "POLYGON"
g_type
end

def spatial_type
@spatial_type
end

def spatial_type=(value)
@spatial_type = value.to_s
end
SpatialIndexDefinition = Struct.new(*IndexDefinition.members, :spatial)

def srid
if @srid
@srid.to_i
else
Mysql2RgeoAdapter::DEFAULT_SRID
module ColumnDefinitionUtils
class << self
def geo_type(type = "GEOMETRY")
type.to_s.delete('_').upcase
end
end

def srid=(value)
@srid = value
def default_srid(options)
options[:geographic] ? 4326 : Mysql2RgeoAdapter::DEFAULT_SRID
end
end
end

SpatialIndexDefinition = Struct.new(*IndexDefinition.members, :spatial)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ActiveRecord
module ConnectionAdapters
module Mysql2Rgeo
VERSION = "1.0.4".freeze
VERSION = "2.0.1".freeze
end
end
end
20 changes: 13 additions & 7 deletions lib/active_record/connection_adapters/mysql2rgeo_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class Mysql2RgeoAdapter < Mysql2Adapter
geometry: {},
geometrycollection: {},
linestring: {},
spatial: { type: "geometry" }.freeze,
point: {},
polygon: {},
multilinestring: {},
multipoint: {},
multipolygon: {},
}.freeze
spatial: { type: "geometry" },
point: {},
polygon: {}
}

# http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
DEFAULT_SRID = 0
Expand All @@ -61,7 +61,13 @@ def supports_spatial?
end

# Returns an array of indexes for the given table.
def indexes(table_name, _name = nil) #:nodoc:
def indexes(table_name, name = nil) #:nodoc:
if name
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Passing name to #indexes is deprecated without replacement.
MSG
end

indexes = []
current_index = nil
execute_and_free("SHOW KEYS FROM #{quote_table_name(table_name)}", "SCHEMA") do |result|
Expand All @@ -78,7 +84,7 @@ def indexes(table_name, _name = nil) #:nodoc:
options.push(true)
Mysql2Rgeo::SpatialIndexDefinition.new(*options)
else
IndexDefinition.new(*options)
IndexDefinition.new(row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], {}, nil, nil, index_type, index_using, row[:Index_comment].presence)
end
end

Expand All @@ -90,7 +96,7 @@ def indexes(table_name, _name = nil) #:nodoc:
indexes
end

def quote(value, column = nil)
def quote(value)
if RGeo::Feature::Geometry.check_type(value)
"ST_GeomFromWKB(0x#{RGeo::WKRep::WKBGenerator.new(hex_format: true, little_endian: true).generate(value)},#{value.srid})"
else
Expand Down
17 changes: 1 addition & 16 deletions test/ddl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_spatial_column_options

def test_type_to_sql
adapter = SpatialModel.connection
assert_equal "GEOMETRY", adapter.type_to_sql(:geometry, "point,4326")
assert_equal "GEOMETRY", adapter.type_to_sql(:geometry, limit: "point,4326")
end

def test_create_simple_geometry
Expand Down Expand Up @@ -270,21 +270,6 @@ def test_non_spatial_column_limits
assert_equal 123, col.limit
end

def test_includes_spatial_types
klass.connection.create_table("spatial_types", force: true, options: "ENGINE=MyISAM") do |t|
t.geometry :geometry_field
t.polygon :polygon_field, null: false, index: { type: :spatial }
t.point :point_field
t.linestring :linestring_field

t.geometry :geometry_multi, multi: true
t.polygon :polygon_multi, multi: true
t.point :point_multi, multi: true
t.linestring :linestring_multi, multi: true
end
klass.reset_column_information
end

private

def klass
Expand Down
1 change: 0 additions & 1 deletion test/spatial_queries_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def test_query_point_wkt
obj.save!
id = obj.id
obj2 = SpatialModel.where(latlon: "POINT(1 2)").first
puts obj2
refute_nil(obj2)
assert_equal(id, obj2.id)
obj3 = SpatialModel.where(latlon: "POINT(2 2)").first
Expand Down
4 changes: 1 addition & 3 deletions test/tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class TasksTest < ActiveSupport::TestCase # :nodoc:
NEW_CONNECTION = {
"adapter" => "mysql2rgeo",
"adapter" => "mysql2rgeo",
"host" => "127.0.0.1",
"database" => "mysql2rgeo_tasks_test",
"username" => "root",
Expand Down Expand Up @@ -79,7 +79,6 @@ def test_basic_geography_schema_dump
ActiveRecord::SchemaDumper.dump(connection, file)
end
data = File.read(tmp_sql_filename)

assert data.index(%(t.geometry "latlon1", limit: {:type=>"point", :srid=>0}))
assert data.index(%(t.geometry "latlon2", limit: {:type=>"point", :srid=>0}))
end
Expand All @@ -94,7 +93,6 @@ def test_index_schema_dump
ActiveRecord::SchemaDumper.dump(connection, file)
end
data = File.read(tmp_sql_filename)

assert data.index(%(t.geometry "latlon", limit: {:type=>"point", :srid=>0}, null: false))
assert data.index(%(t.index ["latlon"], name: "index_spatial_test_on_latlon", type: :spatial))
end
Expand Down

0 comments on commit 679bec4

Please sign in to comment.