Skip to content

Commit

Permalink
Expose mysql geometrycollection-like types only via multi-option for …
Browse files Browse the repository at this point in the history
…regular ones
  • Loading branch information
Vasfed committed Feb 2, 2017
1 parent 6e05b69 commit e45bca8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 36 deletions.
Expand Up @@ -1056,25 +1056,25 @@ def type

class MysqlGeometryCollection < ActiveModel::Type::Binary # :nodoc:
def type
:multi_geometry
:geometry
end
end

class MysqlMultiPoint < MysqlGeometryCollection # :nodoc:
def type
:multi_point
:point
end
end

class MysqlMultiLineString < MysqlGeometryCollection # :nodoc:
def type
:multi_linestring
:linestring
end
end

class MysqlMultiPolygon < MysqlGeometryCollection # :nodoc:
def type
:multi_polygon
:polygon
end
end

Expand Down
Expand Up @@ -19,6 +19,10 @@ def auto_increment?
def virtual?
/\b(?:VIRTUAL|STORED|PERSISTENT)\b/.match?(extra)
end

def multi?
/^(geometrycollection|multi)/i.match?(sql_type)
end
end
end
end
Expand Down
Expand Up @@ -55,40 +55,24 @@ def unsigned_decimal(*args, **options)
args.each { |name| column(name, :unsigned_decimal, options) }
end

def geometry(*args, **options)
return multi_geometry(*args, **options) if options[:multi] == true
args.each { |name| column(name, :geometry, options) }
def geometry(*args, multi: false, **options)
type = multi ? :multi_geometry : :geometry
args.each { |name| column(name, type, options) }
end

def point(*args, **options)
return multi_point(*args, **options) if options[:multi] == true
args.each { |name| column(name, :point, options) }
def point(*args, multi: false, **options)
type = multi ? :multi_point : :point
args.each { |name| column(name, type, options) }
end

def linestring(*args, **options)
return multi_linestring(*args, **options) if options[:multi] == true
args.each { |name| column(name, :linestring, options) }
def linestring(*args, multi: false, **options)
type = multi ? :multi_linestring : :linestring
args.each { |name| column(name, type, options) }
end

def polygon(*args, **options)
return multi_polygon(*args, **options) if options[:multi] == true
args.each { |name| column(name, :polygon, options) }
end

def multi_geometry(*args, **options)
args.each { |name| column(name, :multi_geometry, options) }
end

def multi_point(*args, **options)
args.each { |name| column(name, :multi_point, options) }
end

def multi_linestring(*args, **options)
args.each { |name| column(name, :multi_linestring, options) }
end

def multi_polygon(*args, **options)
args.each { |name| column(name, :multi_polygon, options) }
def polygon(*args, multi: false, **options)
type = multi ? :multi_polygon : :polygon
args.each { |name| column(name, type, options) }
end
end

Expand Down
Expand Up @@ -14,6 +14,7 @@ def column_spec_for_primary_key(column)
def prepare_column_options(column)
spec = super
spec[:unsigned] = "true" if column.unsigned?
spec[:multi] = "true" if column.multi?

if supports_virtual_columns? && column.virtual?
spec[:as] = extract_expression_for_virtual_column(column)
Expand Down
8 changes: 4 additions & 4 deletions activerecord/test/cases/adapters/mysql2/spatial_types_test.rb
Expand Up @@ -31,10 +31,10 @@ class Mysql2SpatialTypesTest < ActiveRecord::Mysql2TestCase
assert_match %r{t.point\s+"point_field"$}, schema
assert_match %r{t.linestring\s+"linestring_field"$}, schema

assert_match %r{t.multi_geometry\s+"geometry_multi"$}, schema
assert_match %r{t.multi_polygon\s+"polygon_multi"$}, schema
assert_match %r{t.multi_point\s+"point_multi"$}, schema
assert_match %r{t.multi_linestring\s+"linestring_multi"$}, schema
assert_match %r{t.geometry\s+"geometry_multi",\s+multi: true$}, schema
assert_match %r{t.polygon\s+"polygon_multi",\s+multi: true$}, schema
assert_match %r{t.point\s+"point_multi",\s+multi: true$}, schema
assert_match %r{t.linestring\s+"linestring_multi",\s+multi: true$}, schema
end

test "schema dump can be restored" do
Expand Down

0 comments on commit e45bca8

Please sign in to comment.