fix(db diff): filter inherited constraints for partitioned tables #4589
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
summary
this pr fixes an issue where
supabase db diffgenerates incorrect migrations for partitioned tables. when a foreign key references a partitioned table, postgresql automatically creates inherited constraints with numeric suffixes (fkey1, fkey2, etc.) for each partition. migra sees these as separate constraints and generates drop/add statements that fail with:error: cannot drop inherited constraint table_name_fkey1 of relation table_nameproblem
when using declarative schemas with partitioned tables:
solution
added a filter that removes alter table statements operating on constraints matching the pattern
fkeyfollowed by digits. this pattern is exclusively used by postgresql for auto-generated inherited constraints. legitimate user-defined constraints (likeusers_id_fkeywithout numeric suffix) are preserved.the fix is applied to both the migra and pgadmin diff paths.
testing
added 7 test cases covering:
closes #4562