Skip to content

Comments

Fix limit data dropped from schema on migrate#440

Open
conorml wants to merge 1 commit intorgeo:10.0-stablefrom
conorml:fix-limit-data-dropped-from-schema-on-migrate
Open

Fix limit data dropped from schema on migrate#440
conorml wants to merge 1 commit intorgeo:10.0-stablefrom
conorml:fix-limit-data-dropped-from-schema-on-migrate

Conversation

@conorml
Copy link

@conorml conorml commented Feb 10, 2026

Add encode_with/init_with methods to SpatialColumn so that spatial attributes (geographic, geometric_type, has_m, has_z, srid, limit) are properly serialized and deserialized during schema cache operations.

Also implement == and hash so that schema change detection correctly compares spatial columns.

Problem: when running rails db:migrate there is always a diff in the schama.rb file for each table of type t.geography ex:
t.geography "lonlat", limit: {:srid=>4326, :type=>"st_point", :geographic=>true}
=>
t.geography "lonlat"

with this change this diff no longer exists as the column is read fully by the adapter.

NOTE: This has been fixed in master, but is still an issue in 10.x and we're not on rails 8.1 yet so still need to stay on 10.x

Add encode_with/init_with methods to SpatialColumn so that spatial
attributes (geographic, geometric_type, has_m, has_z, srid, limit)
are properly serialized and deserialized during schema cache operations.

Also implement == and hash so that schema change detection correctly
compares spatial columns.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Member

@keithdoggett keithdoggett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks fine. I'm just trying to figure out the exact issue here. Is the limit method not working or is it specifically when loading data in with YAML via init_with and encode_with?

I'm not super familiar with how that version of the schema generator works so just trying to think through if there's a better way to handle this or if some other method is not working and this is just a patch over top of that. Thanks!

@keithdoggett keithdoggett requested a review from BuonOmo February 12, 2026 19:51
@conorml
Copy link
Author

conorml commented Feb 13, 2026

I think this looks fine. I'm just trying to figure out the exact issue here. Is the limit method not working or is it specifically when loading data in with YAML via init_with and encode_with?

I'm not super familiar with how that version of the schema generator works so just trying to think through if there's a better way to handle this or if some other method is not working and this is just a patch over top of that. Thanks!

It doesn't seem to actually affect the limit method at runtime, but just what is exported to the schema on update. The way I understand it is that if you clean out your schema and run export the schema it works fine. The problem comes if you try to update the schema after running the application. So when activestorage initialized and calls deduplicate it drops limit when it updates the schema cache. And so then when updating the schema file using the schema cache the geography column no longer have the limit data and so the schema for those columns gets updated correctly. So you can fix this by just clearing the schema cache after running the application and it works fine, but it's just a pain to have to either do that or to make sure to reject these changes to the schema file if they get updated incorrectly.

It's here where the column gets deduplicated and without this change lose the limit property: https://github.com/rails/rails/blob/bb2bdef2925433a0c5db31b873f9faddf2e2e65d/activerecord/lib/active_record/connection_adapters/column.rb#L104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants