Skip to content

A renamed temporal foreign key asks the in-the-way rules before it becomes a rename (#196) - #198

Merged
CaffeinatedCoder merged 1 commit into
release/5.xfrom
fix/196-temporal-fk-rename-in-the-way
Oct 23, 2026
Merged

CaffeinatedCoder merged 1 commit into
release/5.xfrom
fix/196-temporal-fk-rename-in-the-way

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #196

Into release/5.x. Found by the focused 5.6.0 sweep (two lenses). Closes acts only on main, 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 ### Fixed line in the root and PostgreSQL changelogs, a sentence in docs/postgresql-constraints.md, and CLAUDE.md.

Tests

  • TemporalForeignKeyRenameTests:
  • 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).
  • With the fix reverted: the three unit tests and the integration test fail (42804: foreign key constraint "FK_tr1_b_bookings_tr1_a_rooms_RoomId_BookedDuring" cannot be implemented).
  • Suites: unit plus PostgreSQL 18/16, 739 passed.

🤖 Generated with Claude Code

…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]>
@CaffeinatedCoder CaffeinatedCoder added this to the 5.6.0 milestone Oct 23, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working severity/medium Inconsistency or failure in a narrow scenario package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints area/migrations The differs, snapshot format, EnsureCreated and design-time wiring labels Oct 23, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 648f752 into release/5.x Oct 23, 2026
13 of 14 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/196-temporal-fk-rename-in-the-way branch October 23, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints area/migrations The differs, snapshot format, EnsureCreated and design-time wiring bug Something isn't working package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL severity/medium Inconsistency or failure in a narrow scenario

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant