Repository navigation
Description
Found by the pre-preview sweep of main @ 948496a (lenses: base operations, new check against the standing rules, and an independent read by GPT); reproduced on PostgreSQL 16 and 18.
What happens
An exclusion constraint is renamed, and the same migration has EF Core create an index under the name it gives up. The migration scaffolds and fails at apply:
CREATE INDEX ex_role_grant_active_period ON role_grants ("RoleId");
ALTER TABLE role_grants RENAME CONSTRAINT ex_role_grant_active_period TO ex_renamed;
-- 42P07: relation "ex_role_grant_active_period" already existsThe same with a default name that changes because a column is renamed, while an index takes the old default name.
Why
A contributor's in-place statements are written after EF Core's operations (SchemaOperationPlanner.cs:156, :208; PgExclusionContributor.cs:142). Drops run before them and creates after, so those two are safe; a rename frees its old name too late. NameClaims.Require (:95) reads the target only, where each name is taken once. The other direction has the same shape and was not run: a constraint renamed to a name an EF Core index gives up in that migration is safe only because the rename comes last.
Scenario
public sealed class RangeNamedOld : ITestModel
{
public static void Build(ModelBuilder modelBuilder)
=> modelBuilder.Entity<RoleGrant>().ToTable("role_grants")
.DeclarePostgres(pg => [pg.Exclusion(pg.Overlaps(x => x.Period), name: "ex_range")]);
}
public sealed class RangeRenamedAndItsOldNameReused : ITestModel
{
public static void Build(ModelBuilder modelBuilder)
{
var grants = modelBuilder.Entity<RoleGrant>().ToTable("role_grants");
grants.HasIndex(x => x.RoleId).HasDatabaseName("ex_range");
grants.DeclarePostgres(pg => [pg.Exclusion(pg.Overlaps(x => x.Period), name: "ex_range_v2")]);
}
}
[TestMethod]
public void A_name_freed_by_a_rename_can_be_taken_in_the_same_migration()
{
using var database = new LiveDatabase();
database.Create<RangeNamedOld>();
database.Migrate<RangeNamedOld, RangeRenamedAndItsOldNameReused>(); // 42P07
CollectionAssert.Contains(database.Exclusions(), "ex_range_v2");
}Change
A direction, to confirm: a rename in place becomes a rebuild when the name it frees is claimed by anything else in the target, or the name it takes was held by anything else in the source. The drop then frees the name before EF Core's operations and the create takes the new one after them. No temporary names.
Test
The pair above in PgExclusionLiveTests, the default-name variant, and the statement order in PgExclusionMigrationTests.
Activity
CaffeinatedCoder commentedon Nov 14, 2026
Measured on PostgreSQL 18 against main @ 010ff31 while fixing this in #137:
fix: a rename in place whose name is held when it runs is a rebuild