Fix limit data dropped from schema on migrate#440
Conversation
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 <[email protected]>
keithdoggett
left a comment
There was a problem hiding this comment.
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 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 |
|
@keithdoggett could you re-run the ci tests? These seem to just be flakey, but want to make sure they can all pass. |
|
@conorml looks like the tests are passing and the changes look good given your explanation. I can get this merged and look into deploying a new version for this major version tomorrow. |
|
Thanks @conorml merged into |
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