Module: ActiveRecord::ConnectionAdapters::PostGIS::SchemaStatements
- Included in:
- ActiveRecord::ConnectionAdapters::PostGISAdapter
- Defined in:
- lib/active_record/connection_adapters/postgis/schema_statements.rb
Instance Method Summary collapse
-
#create_table_definition(*args, **kwargs) ⇒ Object
override.
-
#new_column_from_field(table_name, field, _definitions) ⇒ Object
override github.com/rails/rails/blob/7-0-stable/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L662 Create a SpatialColumn instead of a PostgreSQL::Column.
-
#spatial_column_info(table_name) ⇒ Object
memoize hash of column infos for tables.
-
#views ⇒ Object
Returns an array of view names defined in the database.
Instance Method Details
#create_table_definition(*args, **kwargs) ⇒ Object
override
45 46 47 |
# File 'lib/active_record/connection_adapters/postgis/schema_statements.rb', line 45 def create_table_definition(*args, **kwargs) PostGIS::TableDefinition.new(self, *args, **kwargs) end |
#new_column_from_field(table_name, field, _definitions) ⇒ Object
override github.com/rails/rails/blob/7-0-stable/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L662 Create a SpatialColumn instead of a PostgreSQL::Column
10 11 12 13 14 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 40 41 42 |
# File 'lib/active_record/connection_adapters/postgis/schema_statements.rb', line 10 def new_column_from_field(table_name, field, _definitions) column_name, type, default, notnull, oid, fmod, collation, comment, identity, attgenerated = field = (column_name, type, oid.to_i, fmod.to_i) default_value = extract_value_from_default(default) default_function = if attgenerated.present? default else extract_default_function(default_value, default) end if (match = default_function&.match(/\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z/)) serial = sequence_name_from_parts(table_name, column_name, match[:suffix]) == match[:sequence_name] end # {:dimension=>2, :has_m=>false, :has_z=>false, :name=>"latlon", :srid=>0, :type=>"GEOMETRY"} spatial = spatial_column_info(table_name).get(column_name, .sql_type) Column.new( column_name, get_oid_type(oid.to_i, fmod.to_i, column_name, type), default_value, , !notnull, default_function, collation: collation, comment: comment.presence, serial: serial, generated: attgenerated, identity: identity.presence, spatial: spatial ) end |
#spatial_column_info(table_name) ⇒ Object
memoize hash of column infos for tables
50 51 52 53 |
# File 'lib/active_record/connection_adapters/postgis/schema_statements.rb', line 50 def spatial_column_info(table_name) @spatial_column_info ||= {} @spatial_column_info[table_name.to_sym] ||= SpatialColumnInfo.new(self, table_name.to_s) end |
#views ⇒ Object
Returns an array of view names defined in the database.
56 57 58 |
# File 'lib/active_record/connection_adapters/postgis/schema_statements.rb', line 56 def views super - %w[geography_columns geometry_columns] end |