Skip to content

Fall back from a rename to drop-first, create-last when it would fail at apply (#141, #143) - #148

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/141-143-rename-placement
Oct 20, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/141-143-rename-placement

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #141
Closes #143

Problem

Renames of complex indexes, exclusion constraints and temporal constraints run after EF Core's operations, and two shapes scaffolded cleanly and failed at apply:

Change

A rename pair now stays a rename only when nothing that runs before it needs the old object gone. Otherwise it becomes a drop under the old name before the base operations and a create/add under the new one after them.

Tests

  • AlterColumnUnderIndexTests: SQL Server, a default-named index on a renamed table and an explicitly renamed index, each under a shrinking column. No RenameIndexOperation; the drop comes before the AlterColumnOperation and the create after it. On PostgreSQL the same model stays a rename.
  • RenameOldNameTakenTests: a native index taking the old name (PostgreSQL and SQL Server), a name swap between two complex indexes, an exclusion constraint against a native unique constraint and against a complex index, and a temporal constraint against a native unique constraint (FK dropped first and re-added last). The index cases walk the operations by name the way the database would. Over-correction guards: a plain rename, a case-only rename on SQL Server, and a plain temporal rename that keeps its FK.
  • PostgresIntegrationTests.Renames.cs: applies the index, exclusion and temporal A complex-index rename runs after a native CREATE INDEX that takes its old name (42P07) #143 migrations on PostgreSQL 18 in one transaction, as database update does.
  • SqlServerIntegrationTests.Alter_column_under_a_renamed_index_applies: applies the SQL Server: a renamed complex index stays in the way of ALTER COLUMN, and the migration fails at apply (Msg 5074) #141 migration (a table rename plus an explicit rename, both under shrinking columns) and checks uniqueness still holds. Not run locally: this Apple Silicon machine has no Rosetta in OrbStack, so the SQL Server container exits. The Integration (SQL Server 2022) CI lane runs it.

Counterfactuals (verify-the-guard), reverting one mechanism at a time:

Reverted Fails
all source changes (HEAD) 8 unit tests; 3 PG integration tests with 42P07: relation "ra_ix_a" / "ra_ex_a" / "ra_uq_a" already exists
in-the-way check for rename pairs both #141 SQL Server tests
old-name check for index renames PG and SQL Server native-index tests, the swap test
exclusion fallback both exclusion tests
temporal fallback the temporal test
FK rebuild with the temporal fallback the temporal test (FK order); live: 2BP01: cannot drop constraint ra_uq_a … because other objects depend on it
self-exclusion in IsIndexNameInUse the SQL Server case-only rename test

Unit suite: 581/581 (TestCategory!=Integration&TestCategory!=SqlServer).

🤖 Generated with Claude Code

… at apply

Renames of complex indexes, exclusion constraints and temporal constraints run
after EF Core's operations. Two shapes failed at apply:

- #141 (SQL Server): the in-the-way check covered kept indexes only, so a
  renamed index stayed on a column an ALTER COLUMN changes (Msg 5074).
- #143: a rename whose old name the target model gives to another object ran
  after EF created that object (PostgreSQL 42P07, a native index or key taking
  the name; also a complex-index name swap).

A rename pair now stays a rename only when neither applies; otherwise it is a
drop under the old name before the base operations and a create under the new
one after them. A temporal constraint that falls back takes its temporal
foreign keys with it, since dropping it under them fails with 2BP01. Names are
checked against the target model: the core's IsIndexNameInUse (complex and
native indexes, keys, under IndexNameScope), and in the PostgreSQL satellite
the inventory ValidateNamesAcrossKinds already built, now TargetNames.

Closes #141
Closes #143

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 severity/high Wrong results, crash or failed writes in a realistic scenario package/core Affects EFCore.ComplexIndexes package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL package/sqlserver Affects EFCore.ComplexIndexes.SqlServer 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
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 bug Something isn't working package/core Affects EFCore.ComplexIndexes package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL package/sqlserver Affects EFCore.ComplexIndexes.SqlServer severity/high Wrong results, crash or failed writes in a realistic scenario

Projects

None yet

1 participant