Module: ActiveRecord::ConnectionAdapters::Mysql2Rgeo::SchemaStatements

Included in:
ActiveRecord::ConnectionAdapters::Mysql2RgeoAdapter
Defined in:
lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb

Instance Method Summary collapse

Instance Method Details

#indexes(table_name) ⇒ Object

override



10
11
12
13
14
15
16
17
18
# File 'lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb', line 10

def indexes(table_name) #:nodoc:
  indexes = super
  # HACK(aleks, 06/15/18): MySQL 5 does not support prefix lengths for spatial indexes
  # https://dev.mysql.com/doc/refman/5.6/en/create-index.html
  indexes.select do |idx|
    idx.type == :spatial
  end.each { |idx| idx.is_a?(Struct) ? idx.lengths = {} : idx.instance_variable_set(:@lengths, {}) }
  indexes
end

#initialize_type_map(m = type_map) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb', line 46

def initialize_type_map(m = type_map)
  super

  %w[
    geometry
    geometrycollection
    point
    linestring
    polygon
    multipoint
    multilinestring
    multipolygon
  ].each do |geo_type|
    m.register_type(geo_type) do |sql_type|
      Type::Spatial.new(sql_type)
    end
  end
end

#native_database_typesObject

override



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb', line 30

def native_database_types
  # Add spatial types
  # Reference: https://dev.mysql.com/doc/refman/5.6/en/spatial-type-overview.html
  super.merge(
    geometry:            { name: "geometry" },
    geometrycollection:  { name: "geometrycollection" },
    linestring:          { name: "linestring" },
    multi_line_string:   { name: "multilinestring" },
    multi_point:         { name: "multipoint" },
    multi_polygon:       { name: "multipolygon" },
    spatial:             { name: "geometry" },
    point:               { name: "point" },
    polygon:             { name: "polygon" }
  )
end

#type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil) ⇒ Object

override



21
22
23
24
25
26
27
# File 'lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb', line 21

def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **) # :nodoc:
  if (info = RGeo::ActiveRecord.geometric_type_from_name(type.to_s.delete("_")))
    type = limit[:type] || type if limit.is_a?(::Hash)
    type = type.to_s.delete("_").upcase
  end
  super
end