Module: ActiveRecord::ConnectionAdapters::PostGIS::SchemaStatements

Defined in:
lib/active_record/connection_adapters/postgis/schema_statements.rb

Instance Method Summary collapse

Instance Method Details

#column_type_for(column_name) ⇒ Object

Override column type lookup to handle PostGIS types



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/active_record/connection_adapters/postgis/schema_statements.rb', line 15

def column_type_for(column_name)
  column_name = column_name.to_s

  # Check if it's a known PostGIS type
  if column_name =~ /^(geometry|geography)/
    # Extract the base type name from definitions like "geometry(Point,4326)"
    base_type = case column_name
    when /\(Point/i then :point
    when /\(LineString/i then :line_string
    when /\(Polygon/i then :polygon
    when /\(MultiPoint/i then :multi_point
    when /\(MultiLineString/i then :multi_line_string
    when /\(MultiPolygon/i then :multi_polygon
    when /\(GeometryCollection/i then :geometry_collection
    when /^geography/i then :geography
    when /^geometry/i then :geometry
    else
                  nil
    end

    return base_type if base_type
  end

  super
end

#columns(table_name) ⇒ Object

Override to handle PostGIS column types



8
9
10
11
12
# File 'lib/active_record/connection_adapters/postgis/schema_statements.rb', line 8

def columns(table_name)
  column_definitions(table_name).map do |field|
    new_column_from_field(table_name, field, @type_map)
  end
end