Repository navigation
fix: drop a temporal foreign key first when its principal table is dropped (#79) - #102
Merged
Merged
Conversation
…opped A migration dropping both tables of a temporal foreign key skipped the key, since its dependent table was going anyway, and EF ordered the DropTable operations without knowing about it. When the principal's table sorted first the migration failed with 2BP01; Down() of the migration that created the two tables has the same shape, so it could not roll back either. The key is now dropped before the base operations whenever its principal table is dropped. Proven by reverting: the differ test finds no DropForeignKeyOperation and the integration test fails with 2BP01 on PostgreSQL 18. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #79
Problem
A migration that drops both the principal table of a temporal foreign key and its dependent table failed at apply whenever the principal's table sorted first:
ApplyTemporalConstraintsdropped a temporal foreign key only when its dependent table survived, and EF ordersDropTableoperations without knowing about the key. TheDown()of the migration that created both tables has the same shape, sodatabase update <previous>andmigrations removeafter applying could not roll back. Whether it failed depended only on the table names.Change
NpgsqlComplexIndexMigrationsModelDiffer.ApplyTemporalConstraints: a source foreign key whose principal table (by its source identity, before any rename) is dropped is now dropped explicitly, before the base operations, even when its dependent table is dropped too. A dependent dropped alone still takes the key with it (the existing "Dropping the dependent table skips explicit temporal FK drop" test still holds).### Fixedline in the root and PostgreSQL changelogs.Tests
NpgsqlTemporalForeignKeyDifferTests.Dropping_both_tables_drops_foreign_key_first_when_principal_sorts_first: diffs a model witha_subscriptions←b_addonsto nothing, asserts EF dropsa_subscriptionsfirst (the premise) and that aDropForeignKeyOperationonb_addonsprecedes the firstDropTableOperation.PostgresIntegrationTests.Temporal_foreign_key_tables_drop_together: createsig_a_rooms←ig_b_reservationswith a row in each, applies the drop-everything diff with the stock generator, and checks both tables are gone.2BP01: cannot drop table ig_a_rooms because other objects depend on it.🤖 Generated with Claude Code