Repository navigation
Give each TPC copy a name of its own, and shorten temporal FK copies (#167, #168) - #176
Merged
Merged
Conversation
…pies (#167, #168) #167: on a TPC base, two partial indexes or exclusion constraints over the same parts must both be named, and an explicit name repeated on every table was refused where index names are unique per schema or database. No input passed on PostgreSQL or SQLite, where 5.4.1 diffed the model cleanly. An explicit name now stays on the declaring type's table. Where index names are unique per schema or database, each other table's copy takes the name followed by its table (CustomMigrationsModelDiffer.CopyName); on SQL Server it repeats per table, as EF Core 10 repeats its own HasIndex name (measured: EF Core's repetition fails on SQLite with "index ... already exists"). A temporal foreign key owns no index and keeps its name on every table. A 5.4.1 snapshot holds the base's table only, so the first migrations add creates the copies and leaves the base's names alone. TpcDeclaration and RepeatedName are gone: no explicit name repeats within a namespace now. #168: a temporal foreign key's default-named copy on a long derived table is shortened among its table's constraints, as #145 shortens the other kinds, on both sides of the diff. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 20, 2026
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 #167
Closes #168
One PR for both. Both change how a TPC copy is named, in the same code path (the copy-name and shortening logic in the core and PostgreSQL differs) and in the same
docs/upgrading.mdparagraph. Split, the second PR would be stacked on the first.Problem
#167. On a TPC base, two partial indexes or two exclusion constraints over the same parts must both be named, because their default names would be one name. On PostgreSQL and SQLite, 5.5.0 refused an explicit name repeated on every table and told you to leave it out. Left out, the declaration failed for lack of a name. No input passed. 5.4.1 diffed the same model cleanly, on the base's table only, so a consumer with this model could not run the first
migrations addafter upgrading.#168. A temporal foreign key's default-named copy on a long derived table was not shortened, as #145 shortens the other kinds. The first
migrations addafter upgrading a 5.4.1 model failed with "… is 74 bytes long", althoughdocs/upgrading.mdsaid such copies are shortened.Change
Naming decision (#167). I measured EF Core 10 with two named, filtered
HasIndexon a TPC base. EF Core repeats the explicit name on every table, on every provider. On SQLiteEnsureCreated()then fails with "index ix_code_active already exists", and PostgreSQL fails with 42P07 the same way. So the package matches EF Core where that works and differs where it can't:{name}_{table}, such asix_code_active_special_bookings. This covers exclusion and temporal constraints too, since each owns an index.IX_{table}_….{name}_{table}) is shortened past the identifier limit as EF Core shortens its own (~,~1, …). A name you wrote that is too long is still refused, now with the advice to shorten it, which works.{name}_{table}.The alternatives were weaker. A per-table name given by the user would need new API before the tag. Distinct default names per filter would leave the siblings unnamed, which the declaration-time rule refuses for good reason, and would rename the base's index for a 5.4.1 model.
Files:
CustomMigrationsModelDiffer.cs:CopyNamedecides each copy's name and whether it may be shortened.TpcDeclarationandRepeatedNameare removed, since no explicit name repeats within a namespace any more, andThrowIfIdentifierTooLongloses its TPC-only advice.NpgsqlComplexIndexMigrationsModelDiffer.cs: exclusion and temporal constraints useCopyName. Temporal foreign keys get a shortening pass (A temporal foreign key's TPC copy on a long derived table is not shortened, and a 5.4.1 model fails at the first migrations add #168), taken among their table's constraints only (indexBacked: false). The cross-kind check loses itsRepeatedNamebranch.docs/upgrading.md(TPC entry), the 5.5.0 lines of the three changelogs, andCLAUDE.md. The PostgreSQL TPC with a long derived table name: the default name is too long and an explicit name repeats, so no name passes #145 line moves from Breaking to Changed: an explicit name no longer fails. No new Changed answers row is needed. A 5.4.1 model now gets what the TPC with a concrete base: complex indexes, exclusion and temporal constraints land on the base table only #93 row describes: the base's table unchanged and copies on the derived tables.Tests
Unit (647 pass):
TpcHierarchyTests: the TPC base with two partial indexes or exclusion constraints over the same parts: no name passes on PostgreSQL or SQLite #167 model gets 6 creates on SQLite and PostgreSQL, each under a distinct per-table name, and 6EXCLUDEstatements. SQL Server gets the names repeated per table. Upgrading from a 5.4.1-shaped model (rendering version 2) creates only the copies, with no drop or rename on the base, and the second diff is empty. Explicit index, exclusion, temporal and FK names are covered, plus a long derived table shortening{name}_{table}. A temporal foreign key's TPC copy on a long derived table is not shortened, and a 5.4.1 model fails at the first migrations add #168: the FK copy isFK_…~, the 5.4.1 upgrade adds only the copies, and nothing churns. The SQLite apply of the TPC base with two partial indexes or exclusion constraints over the same parts: no name passes on PostgreSQL or SQLite #167 model runs in memory, and both partial indexes enforce on the derived table under their names.SnapshotRoundTripTests: the TPC base with two partial indexes or exclusion constraints over the same parts: no name passes on PostgreSQL or SQLite #167 model through a compiled snapshot has no churn. A pre-5.5.0 compiled snapshot creates only the copies under the expected names. A temporal foreign key's TPC copy on a long derived table is not shortened, and a 5.4.1 model fails at the first migrations add #168 from a compiled pre-5.5.0 snapshot gives the shortened FK copy, and the long-table round trip now includes the FK.UnmappedDeclarationTests: an explicit name on an abstract TPC base becomesix_animal_id_catsandix_animal_id_dogs.Live PostgreSQL 18 (
PostgresIntegrationTests, all 34 PG 16/18 integration tests pass):pg_indexshows the base's names unchanged and the derived table's four…_ig_tpc_vip_siblingsnames. The derived table rejects with 23505 underix_sib_active_…andix_sib_archived_…, and with 23P01 underex_sib_active_…andex_sib_revoked_…. A revoked row may overlap an active one.ConstraintNameis the shortenedFK_…~name.Live SQL Server:
SqlServerIntegrationTests.Tpc_named_partial_siblings_apply_on_every_tableapplies the #167 model, reads both filtered indexes back fromsys.indexeson each table, and checks that both enforce. It ran in the CI lane on a throwawayproof/167-sqlserverbranch (see below).Reverted, per verify-the-guard:
CopyName's{name}_{table}reverted to the explicit name: 14 tests fail, each with the name-collision refusal.🤖 Generated with Claude Code