Skip to content

Give each TPC copy a name of its own, and shorten temporal FK copies (#167, #168) - #176

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/167-168-tpc-copy-names
Oct 20, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/167-168-tpc-copy-names

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

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.md paragraph. 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 add after 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 add after upgrading a 5.4.1 model failed with "… is 74 bytes long", although docs/upgrading.md said such copies are shortened.

Change

Naming decision (#167). I measured EF Core 10 with two named, filtered HasIndex on a TPC base. EF Core repeats the explicit name on every table, on every provider. On SQLite EnsureCreated() 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:

  • Explicit name, declaring type's table: keeps the name. A 5.4.1 snapshot holds exactly these names, so nothing churns.
  • Explicit name, other tables, PostgreSQL and SQLite (index names unique per schema or database): {name}_{table}, such as ix_code_active_special_bookings. This covers exclusion and temporal constraints too, since each owns an index.
  • Explicit name, SQL Server (index names per table): repeats on every table, as EF Core does. Unchanged from eff80b4.
  • Temporal foreign key: keeps its explicit name on every table. It owns no index, and PostgreSQL keeps constraint names per table.
  • Default names: unchanged, IX_{table}_….
  • Shortening: any name the package makes up (a default name with more than one table, or {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.
  • Abstract base: it has no table of its own, so every copy takes {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:

Tests

Unit (647 pass):

Live PostgreSQL 18 (PostgresIntegrationTests, all 34 PG 16/18 integration tests pass):

Live SQL Server: SqlServerIntegrationTests.Tpc_named_partial_siblings_apply_on_every_table applies the #167 model, reads both filtered indexes back from sys.indexes on each table, and checks that both enforce. It ran in the CI lane on a throwaway proof/167-sqlserver branch (see below).

Reverted, per verify-the-guard:

🤖 Generated with Claude Code

…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]>
@CaffeinatedCoder CaffeinatedCoder added this to the 5.5.0 milestone Oct 20, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working breaking Changes an answer or a signature — needs a major severity/high Wrong results, crash or failed writes in a realistic scenario package/core Affects EFCore.ComplexIndexes package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL area/indexes Complex-property, composite, unique and filtered indexes area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints area/migrations The differs, snapshot format, EnsureCreated and design-time wiring labels Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 9cd0121 into main Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/167-168-tpc-copy-names branch October 20, 2026 13:33
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/indexes Complex-property, composite, unique and filtered indexes area/migrations The differs, snapshot format, EnsureCreated and design-time wiring breaking Changes an answer or a signature — needs a major bug Something isn't working package/core Affects EFCore.ComplexIndexes package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL severity/high Wrong results, crash or failed writes in a realistic scenario

Projects

None yet

1 participant