Repository navigation
Description
Found by the pre-preview sweep of main @ 948496a (GPT's read of the planner; reproduced in a scratch test).
What happens
Reservation is the concrete root of a TPC hierarchy, with Stay and Hold in tables of their own. DeclarePostgres on Reservation gives:
CREATE EXTENSION IF NOT EXISTS btree_gist;
ALTER TABLE reservations ADD CONSTRAINT ex_res EXCLUDE USING gist ("RoomId" WITH =, "Period" WITH &&);Nothing for stays and holds, and no error. Overlapping rows in either derived table are accepted. EF Core gives an index declared on a TPC root to every table of the hierarchy, and 5.x gave each table its copy of an exclusion constraint, so a consumer expects the same here.
An abstract root is refused today ("is not mapped to a table. The declaration would produce nothing, without an error."). The 5.x reader refuses a TPC root with derived types too (ComplexIndexes5xExclusionReader.cs:54). A declaration written here on a concrete root is the one case that passes.
Scenario
public sealed class Declared : ITestModel
{
public static void Build(ModelBuilder b)
{
var pg = PgSchema.For<TpcReservation>();
b.Entity<TpcReservation>().UseTpcMappingStrategy().ToTable("reservations")
.DeclarePostgres(_ => [pg.Exclusion(pg.Equal(x => x.RoomId).Overlaps(x => x.Period), name: "ex_res")]);
b.Entity<TpcStay>().ToTable("stays");
b.Entity<TpcHold>().ToTable("holds");
}
}
// Contexts.Diff<Bare, Declared>().Shape(): the two statements above, both for "reservations".Change
Until the resolver has TPC (#43: the tables a declaration lands on, each copy resolved against its table's entity type), refuse a declaration on an entity type that is mapped with TPC and has derived types, where the migration leads, naming #43's limit. A declaration on a leaf type stays allowed: its table is its own.
Test
The model above refused in PgExclusionMigrationTests, a leaf declaration accepted, and the guard shown to fail without the check.
Activity