Skip to content

fix: a declaration on a derived type that shares its table is refused, where the migration leads - #86

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/derived-type-of-shared-table
Nov 12, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/derived-type-of-shared-table

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Closes #82

Problem

Stay and Hold derive from Reservation in one table. An exclusion constraint declared on Stay was added to the table with nothing in it that says "stay", so two overlapping Hold rows were refused with 23P01. The migration applied, and the database refused writes the model allows. 5.x and EF Core's own HasIndex behave the same way.

Change

Decided by the maintainer on 2026-11-12: refuse it. The planner refuses a declaration on an entity type that shares its table with a base type, naming the topmost such type to declare it on. It is a kernel rule, so it holds for every contributor.

  • On the target side only. A snapshot that holds such a declaration, from an earlier version or from 5.x, describes an object the database has. With the declaration moved to the base type it resolves to the same object, and the migration is empty. Refused on the source side too, there would be no way off such a snapshot.
  • A derived type with a table of its own (TPT) declares as before.

What it costs

A column only the derived type has cannot be named from the base type, so an object on it cannot be declared while the two share a table. A test holds that as a fact, and #85 has the options.

Tests

426 kernel and 62 PostgreSQL tests without a server. No statement that reaches a server changed.

  • Kernel, on three providers: the refusal, with both type names in the message, from GetDifferences and from HasDifferences. Declared on the base type, and on a derived type with its own table, the object is created. A snapshot with the declaration on the derived type diffs to nothing against the base-type model, and its object can be dropped.
  • PostgreSQL: the Stay / Hold model of the issue is refused; on Reservation the create script has the constraint.

Each guard shown to fail, in a scratch copy:

Mutation Fails
No refusal A_declaration_on_a_derived_type_that_shares_its_table_is_refused ×3, A_constraint_on_a_derived_type_…_is_refused
Refused on the source side too A_snapshot_that_holds_one_is_read_and_moving_it_to_the_base_type_costs_nothing, the PostgreSQL test's last assertion
Any derived type refused, own table or not On_the_base_type_or_on_a_derived_type_with_a_table_of_its_own_it_is_declared

🤖 Generated with Claude Code

…, where the migration leads

Closes #82.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 12, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL area/constraints Exclusion constraints, row guards and other constraint-like objects severity/medium Inconsistency or failure in a narrow scenario labels Nov 12, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit dc617a5 into main Nov 12, 2026
7 of 8 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/derived-type-of-shared-table branch November 12, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/constraints Exclusion constraints, row guards and other constraint-like objects bug Something isn't working package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL severity/medium Inconsistency or failure in a narrow scenario

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An exclusion constraint declared on a derived type of a shared table covers its siblings' rows

1 participant