Skip to content

feat: a 5.x snapshot with exclusion constraints moves over with no operations - #94

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
feat/pg-exclusion-5x-reader
Nov 12, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
feat/pg-exclusion-5x-reader

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #92

Problem

A project that comes from EFCore.ComplexIndexes 5.x has its exclusion constraints in the snapshot as 5.x stored them, in the annotation CustomExclusion:Constraints. The planner read only SchemaKit's own annotations. The first migrations add after the move therefore saw no constraint in the snapshot and wrote an ADD CONSTRAINT for each one the model declares, which fails at apply (42P07) on a database that already has them.

Change

  • The kernel has the seam. LegacyDeclarationReader<TDeclaration> reads an earlier package's annotation into declarations, and AddLegacyDeclarationReader<TReader>() registers it. Both carry SK9001 like the rest of the contract. The planner asks the readers for the source side of a diff and resolves what they return like any declaration. In the model a migration leads to, the annotation is refused.
  • The PostgreSQL package reads CustomExclusion:Constraints into PgExclusion (Legacy/Internal/ComplexIndexes5xExclusionReader). What 5.x could store and PgExclusion cannot say is refused by name, with the way off it: a constraint of equality elements only, an access method other than GiST and one-element SP-GiST, a constraint on the root of a TPC hierarchy, and any property 5.x never wrote.
  • A fixture from the published package. test/Fixtures/ComplexIndexes5x/generate.sh builds a net10.0 consumer of EFCore.ComplexIndexes.PostgreSQL 5.6.0 from nuget.org outside the repository and scaffolds its first migration. The snapshot and the migration are checked in as scaffolded; the tests compile them as they are. The model holds every form 5.x could store: the two-argument overload with its default name, a lambda filter, a string filter with a placeholder, explicit names, both deferrals, a verbatim expression, a path through a complex type, a table in a schema with mapped column names, and SP-GiST.

Tests

Locally: 468 kernel tests, 103 PostgreSQL tests offline, 38 on a live server, on PostgreSQL 16.15 and 18.6.

  • The handover. The 5.x snapshot against the same model declared with SchemaKit is no operations, and HasDifferences is false.
  • The catalog decides whether that is right. 5.x's migration is applied as scaffolded; the database then holds exactly the five constraints EnsureCreated() builds for the SchemaKit model, by pg_get_constraintdef. A constraint 5.x built still refuses an overlap (23P01).
  • A difference is not taken for none. Another name is one RENAME CONSTRAINT, another condition a drop and an add, and both apply to the database 5.x built. Against a model that declares nothing, all five constraints are dropped under the names 5.x gave them.
  • Every refusal, 19 rows, and the kernel's seam on its own contributor: read at the source, refused in the target, a value that is no text, a reader that returns null, a reader without a contributor, a class that is no reader, a reader added twice.

Guards shown to fail. 26 defects were seeded one at a time in a scratch copy, and each failed the test meant for it: the planner asking no reader, the target not refused, each of the reader's rules (TPC, the method's case, SP-GiST taking the first of several parts, both deferral mappings, an unknown property passed over, the filter or the name left out, the parts reversed, an expression read as a column), the registration removed from the package, the mark removed from the new method. One is worth naming: with SchemaKit's default name prefix changed, the handover test still passes offline, since both sides go through one resolver. The drop statements of the undeclared model and the catalog comparison on the live server are what fail.

Decisions in this PR that are not confirmed

  • The reader does not resolve by 5.x's rules. The plan (3.13) says "resolved by the 5.x rules frozen in a Legacy namespace". 5.x's descriptor quotes every name and SchemaKit writes a name as the provider does, so the two would never compare equal as text. The reader instead produces the PgExclusion that declares the same object, and the kernel resolves it. The fixture and the catalog comparison are what say the two agree; the plan carries a dated note.
  • The seam is public and part of the contract (SK9001), so another package can read its own predecessor. It could be internal with InternalsVisibleTo, which the PostgreSQL package deliberately does not have.
  • The annotation in the target model is an error, not ignored.
  • An equality-only constraint, and an access method outside GiST and SP-GiST, stop the move until the consumer removes them with 5.x. The alternative is a PgExclusion that can say them.
  • TPC is refused until SchemaResolver: paths to columns and SQL, identically on both sides of a diff #43 rather than read as one constraint.

Not in this PR

🤖 Generated with Claude Code

…erations

The kernel gets LegacyDeclarationReader<TDeclaration>: a reader for an earlier
package's annotation, asked for the source side of a diff and refused in the
target. The PostgreSQL package reads 5.x's CustomExclusion:Constraints into
PgExclusion, and refuses by name what PgExclusion cannot say.

The fixture under test/Fixtures/ComplexIndexes5x is scaffolded by the
published EFCore.ComplexIndexes.PostgreSQL 5.6.0 on net10.0 and checked in as
scaffolded. Its snapshot diffs to nothing against the same model declared with
SchemaKit, and the database its migration builds has the catalog
EnsureCreated() builds, on PostgreSQL 16 and 18.

Closes #92

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 enhancement New feature or request 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 labels Nov 12, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 777dcb7 into main Nov 12, 2026
7 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the feat/pg-exclusion-5x-reader branch November 12, 2026 15:17
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 enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PgExclusion: the 5.x reader, and a 5.x snapshot with exclusion constraints hands over with no operations

1 participant