Support FK's switching between non-castable types
Currently, if switching between incompatible types with a FK, plan validation will error. We need to identify if types are incompatible and drop and re-add the FK
This is probably a pretty rare operation , since the only incompatible type switches we currently support is BIGINT to TIMESTAMP
I'd like to work on this issue!
Sweet! This shouldn't be too much code, but it does get into the nitty gritty of the internal of the library.
There are couple parts to this:
- Identifying if types are castable. I think your best bet is to fetch casts from the systems catalog, but you should validate this is true
- I think all you need to do is check if the underlying column(s) of the FK are changing between non-castable types. You shouldn't need to check the foreign table, since the data type changes should inherently be identical. If they are non-castable, return requiresRecreate=true from this func
This ticket airs a bit more on the tricky side, so definitely let me know if you have any questions
@bplunkett-stripe Hello, just made this draft PR: https://github.com/stripe/pg-schema-diff/pull/73. It only handles bigint to timestamp for now and the logic should probably be structured a bit differently, but please let me know if I'm going in the right direction! Sorry this took a while, didn't work a lot with Go and SQL so had a bit of a learning curve :)