Repository navigation
A renamed temporal foreign key asks the in-the-way rules before it becomes a rename (#196) - #198
Merged
CaffeinatedCoder merged 1 commit intoOct 23, 2026
Conversation
…it becomes a rename A temporal foreign key whose drop and add differ only by name became RENAME CONSTRAINT, placed after the base operations, and its only guard was the #143 name-in-use check. The index, exclusion and temporal constraint rename paths also ask whether the object is in the way; the foreign key path did not. So #188 (a retyped key column) and #187 (a rebuilt or changed principal constraint) did not reach a key whose name changed in the same migration, and a default name changes with the principal table's: 42804 or 2BP01 at apply. The pair now stays a drop before and an add after when the key is in the way (ForeignKeyInTheWay), its principal constraint is rebuilt or changed, or its old name is taken. Closes #196 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 #196
Into
release/5.x. Found by the focused 5.6.0 sweep (two lenses).Closesacts only onmain, so #196 is closed by hand after the merge.Problem
A temporal foreign key whose drop and add differ only by name became
RENAME CONSTRAINT, placed after the base operations, and its only guard was #143's name-in-use check. The index, exclusion and temporal-constraint rename paths also ask whether the object is in the way; the foreign key path didn't. So #188 (a retyped key column) and #187 (a rebuilt or changed principal constraint) didn't reach a key whose name changes in the same migration. A default name contains the principal table's name, so renaming that table is enough. The migration failed when it ran, with 42804 for a retype or 2BP01 when the principal constraint is rebuilt.Change
NpgsqlComplexIndexMigrationsModelDiffer.ApplyTemporalConstraints: in the FK rename loop, the pair stays a drop before and an add after the base operations when any of these holds:ForeignKeyInTheWay(renamed),DependsOnRebuiltConstraint(renamed),DependsOnChangedTemporalConstraint(…), or the old name is in use (#143). That matches the other three rename paths.Also: a
### Fixedline in the root and PostgreSQL changelogs, a sentence indocs/postgresql-constraints.md, and CLAUDE.md.Tests
TemporalForeignKeyRenameTests:ALTER COLUMNs and adds it after.name:change plus a retype.RENAME CONSTRAINT.PostgresIntegrationTests.Renamed_temporal_foreign_key_with_key_retype_applies(PostgreSQL 18), both variants with a row in each table: the migration applies, the key exists under its new name, and it rejects an orphan booking (23503).42804: foreign key constraint "FK_tr1_b_bookings_tr1_a_rooms_RoomId_BookedDuring" cannot be implemented).🤖 Generated with Claude Code