Skip to content

Commit

Permalink
Merge pull request #377 from CodeursenLiberte/master
Browse files Browse the repository at this point in the history
overload type_to_sql
  • Loading branch information
keithdoggett committed Apr 26, 2023
2 parents b831aee + 23fa502 commit 69f89aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ class TableDefinition < PostgreSQL::TableDefinition # :nodoc:

# super: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
def new_column_definition(name, type, **options)
if (info = PostGISAdapter.spatial_column_options(type.to_sym))
col_type = if type.to_sym == :virtual
options[:type]
else
type
end

if (info = PostGISAdapter.spatial_column_options(col_type))
if (limit = options.delete(:limit)) && limit.is_a?(::Hash)
options.merge!(limit)
end
Expand Down
12 changes: 12 additions & 0 deletions test/ddl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,18 @@ def test_column_comments
assert_equal 'Comment test', col.comment
end

def test_generated_geometry_column
skip "Virtual Columns are not supported in this version of PostGIS" unless SpatialModel.connection.supports_virtual_columns?
klass.connection.create_table(:spatial_models, force: true) do |t|
t.st_point :coordinates, limit: { srid: 4326 }
t.virtual :generated_buffer, type: :st_polygon, limit: { srid: 4326 }, as: 'ST_Buffer(coordinates, 10)', stored: true
end
klass.reset_column_information
col = klass.columns.last
assert_equal(:geometry, col.type)
assert(col.virtual?)
end

private

def klass
Expand Down

0 comments on commit 69f89aa

Please sign in to comment.