Developing rails websites with a geographic component we rely heavily on Postgis, so we use activerecord-postgis-adapter for the Postgis support, and I always use schema_plus because it allows me to define views. Until recently, I always had to use the structure.sql instead of the schema.rb because the geometric columns did not dump correctly.
But for a while now, activerecord-postgis-adapter handles this correctly and so we use the schema.rb file again. Only to discover a "new" error:
ActiveRecord::StatementInvalid: PG::DependentObjectsStillExist: ERROR: cannot drop view geography_columns because extension postgis requires it
HINT: You can drop extension postgis instead.
: DROP VIEW IF EXISTS "geography_columns"
Apparently specific Postgis views are also dumped in the schema file, and those views obviously cannot simply be re-created.
A very naive solution I kept using was to comment those create_view lines in our schema.rb file. But apparently there is a much better solution: you can configure which tables and views schema_plus should ignore.
So I added an initializer in /initializers/schema_dumper.rb with the following content:
ActiveRecord::SchemaDumper.ignore_tables = [
"geography_columns", "geometry_columns", "spatial_ref_sys", "raster_columns", "raster_overviews"
]
And now my schema.rb is correct, and simple commands as rake db:setup or rake db:test:prepare just work. Hehe.
Comments
Add comment