Repository navigation
Description
Found by a pre-release sweep of main @ 934ec55; reproduced in a scratch test.
Problem
Index renames run after the base operations (CustomMigrationsModelDiffer.cs:309). When a native HasIndex in the target takes the name a complex index is renamed away from, EF's CREATE INDEX runs while the old index still holds that name. ValidateNoNativeIndexNameCollision checks target names only, so it passes.
Model: v1 HasComplexIndex(x => x.Email.Value, indexName: "ix_a"); v2 HasComplexIndex(x => x.Email.Value, indexName: "ix_b") plus HasIndex(x => x.Code).HasDatabaseName("ix_a").
CREATE INDEX ix_a ON members ("Code"); -- 42P07: ix_a still exists
ALTER INDEX ix_a RENAME TO ix_b;
Exclusion and temporal constraint renames are built the same way (NpgsqlComplexIndexMigrationsModelDiffer.cs:726-760, :893-910): traced, not run.
Change
When a rename's old name is taken by a base CreateIndexOperation (or a constraint add, for the constraint renames), fall back to dropping first and creating last.
Tests
An NpgsqlDiff test: no RenameIndexOperation named ix_a after the CreateIndexOperation named ix_a. The same for an exclusion constraint rename against a native unique constraint taking its old name.
Outcome (PR #148)
The constraint renames reproduced: on PostgreSQL 18, an exclusion or temporal constraint renamed away from a name that a native unique constraint takes fails with 42P07. Two more shapes have the same cause and are fixed in the same PR. First, two complex indexes swapping names, where RENAME ix_c TO ix_b runs while ix_b still exists. Second, a temporal constraint that falls back to drop-and-add must take its temporal foreign keys with it, or the drop fails with 2BP01 (verified live). The old name is checked against the target model, not against the operations: anything the target gives that name to, in the namespace the provider uses.
Activity
Merge pull request #148 from CaffeinatedCoder/fix/141-143-rename-plac…