Repository navigation
Shorten the default names of TPC copies over the identifier limit - #149
Merged
Merged
Conversation
On a TPC type with derived tables, a copy's default name that runs past the provider's identifier limit is shortened as EF Core 10's Uniquifier shortens its own: cut and marked '~', then '~1', '~2', ... against the names already taken in the scope (this package's names, EF's indexes and keys, and for constraints the table's foreign keys and checks). Measured as the provider measures, so on PostgreSQL it cuts to 63 bytes at a whole character. Complex indexes, exclusion constraints and temporal constraints. Every other default name keeps the 5.2.0 refusal; an explicit name too long on a TPC type is told to leave the name out instead of to shorten it, since a shorter explicit name would repeat on every table. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 18, 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 #145
Problem
On PostgreSQL, a declaration on a TPC type whose derived table has a long name could not be named at all. With
BookingTPC onbookings,HasComplexIndex(x => x.Code, isUnique: true)andSpecialBookingonspecial_bookings_for_corporate_customer_accounts_xyz_1234(57 characters):IX_special_bookings_for_corporate_customer_accounts_xyz_1234_Code(65 bytes) was refused byThrowIfIdentifierTooLong, whose message said to give an explicit, shorter name;TpcDeclaration.RepeatedName, since it repeats on every table, and that message said to leave the name out.Exclusion constraints (
EX_…_RoomId_During) and temporal constraints (AK_…) hit the same dead end. EF Core's ownHasIndexon the same model scaffolds, because EF shortens the name.Change
Decision on the issue: shorten TPC copies only.
CustomMigrationsModelDiffer.ShortenIdentifiershortens a name the way EF Core 10'sUniquifier.Uniquify/Truncatedoes (decompiled from 10.0.0): cut to the limit and end with~, then~1,~2, … for as long as the result is taken. It measures throughMeasureIdentifier, so on PostgreSQL the cut is at 63 bytes and at a whole character. For ASCII names the result matches EF's exactly.IsLongDefaultCopyNamelimits shortening to the default name of a copy whose declaration has aTpcDeclarationorigin (more than one table), when that name is overGetMaxIdentifierLength. Every other default name keeps the 5.2.0 refusal.ExtractAllIndexDescriptors→ShortenIndexCopyNames): names are made unique under the provider'sIndexNameScope/IndexNameComparer, against this package's other complex indexes and EF's own indexes and keys. EF shortens its native index over (Code, RoomId) on that table to the same…_C~.BuildExclusionDescriptors,BuildDescriptors→ShortenConstraintCopyNames): names are made unique among the relations of the schema (indexes, keys, other constraints of the same kind) and among the constraints of the table (foreign keys, checks).ValidateNamesAcrossKindssees the shortened names, because it calls the same builders.RepeatedName's advice mentions the shortening.docs/upgrading.mddescribe the new behaviour. TPC copies are new in the unreleased 5.5.0, so this needs no rendering-version gate.Tests
TpcHierarchyTestscover:IX_…_C~), an exclusion constraint and a temporal constraint (51-character table →EX_…_RoomId_~,AK_…_RoomId_~), each scaffolding;~/~1for two copies sharing a 62-byte prefix, for copies on two long sibling tables (unique per schema), and against EF's own shortened native name;SnapshotRoundTripTests.Tpc_shortened_copy_names_roundtrip_is_noop: a Roslyn-compiled snapshot against the live model gives no operations.PostgresIntegrationTests.Tpc_long_derived_table_applies_shortened_names: on PostgreSQL 18 the names inpg_classare the scaffolded ones, unchanged, and the 23505/23P01 violations report them asConstraintName.main, 10 of the 11 new tests fail. Each throws theThrowIfIdentifierTooLongrefusal (… is 65 bytes long, but the provider allows at most 63), except the advice test, which fails on the missing "Leave the name out". The over-correction guard passes either way, as designed.TestCategory!=Integration&TestCategory!=SqlServer): 578/578. PostgreSQL 18 + 16 integration: 26/26.migration-safety-reviewrun over the diff: names are rendered at design time, no new operations or ordering, the round trip is covered. The one gap it raised, sibling tables that agree past the cut, now has a test (above).🤖 Generated with Claude Code