Skip to content

The factory starts an exclusion constraint's elements with an operator of one's own - #278

Merged
CaffeinatedCoder merged 3 commits into
mainfrom
claude/dreamy-carson-502d61
Nov 29, 2026
Merged

CaffeinatedCoder merged 3 commits into
mainfrom
claude/dreamy-carson-502d61

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #257

Problem

The elements of an exclusion constraint could begin only with pg.Equal(…) or with pg.Overlaps(…), and pg.Overlaps takes Npgsql's own ranges alone. WithUncheckedOperator was on what those two return and not on the factory. So a constraint over another library's range alone, or with that range first, had no lambda form, and was written as records with the property by its name:

new PgExclusion.Gist([new ExclusionElement(new KeyTarget.Column(nameof(Booking.Period)), ExclusionOperator.Overlaps)])

A package outside this repository could offer a typed Overlaps after another element and none that starts the elements.

Change

As decided on 2026-11-29 in the issue:

  • PgSchema<TEntity>.WithUncheckedOperator<TValue>(key, operator), with the chained form's parameters, returns ExclusionElements<TEntity>. It goes through Exclusions.Unchecked, so = is refused with the chained form's message. Public, with no SK9001.
  • Nothing else is added to the surface. "The range first, then an equality element" needed no more than the one method: ExclusionElements<TEntity>.Equal was there. ExclusionElements<TEntity> and ExclusionDraft<TEntity> still have no public constructor.
  • The stored form does not move. A declaration made with the starting form is value for value the one the records make.

Both of these compile and reach the database:

pg.Exclusion(pg.WithUncheckedOperator(x => x.Period, "&&"))                       // the range alone
pg.Exclusion(pg.WithUncheckedOperator(x => x.Period, "&&").Equal(x => x.RoomId))  // the range first

Pages: the README's section on ValueRanges (the bullet that sent the range alone to records, and the row under what the preview does not do), the PostgreSQL package's README (one sentence), the guide's two rows for WithColumn and WithOverlaps, design/schemakit-api.md (P2, the table of what the compiler cannot see, 10.2, one row of section 13), the changelog under ### Added, and CLAUDE.md.

In section 13 of the design the row for WithExpression(sql, "=") said .WithUncheckedOperator(x => Sql.Raw<T>("…"), "="), which throws. It now says .Equal(x => Sql.Raw<T>("…")), as the guide does.

Tests

In the PostgreSQL package's tests:

  • PgExclusionDeclarationTests: the starting form makes the records' declaration, and the typed form's; = is refused with the chained form's message; a model written with the factory stores the keys and values of the same model written as records, and the two diff to nothing both ways.
  • PgExclusionProbeTests (new): the design's P2 and each starting form compiled against the shipped assembly with nothing suppressed, beside the draft of equality elements that must not compile (CS1503), the typed Overlaps over another type (CS0411), and a call without an operator (CS7036).
  • ConsumerCompileTests: the consumer's model has both starting forms.

In the cross-tests with ValueRanges:

  • SatelliteSurfaceTests: Nothing_public_starts_the_elements_with_an_operator_of_ones_own became The_factory_starts_the_elements_with_an_operator_of_ones_own_and_hands_out_no_other_way. TypedOverlaps has the starting Overlaps, an extension of PgSchema<TEntity>, and A_typed_Overlaps_that_starts_the_elements_is_the_declaration_written_as_records holds it to the records.
  • The four models over a range alone are written with the factory. Bookings.DuringAloneAsRecords keeps the records' form, and Written_with_the_factory_a_constraint_is_the_declaration_a_snapshot_holds_from_the_records holds one key and one value, in the model and in the scaffolded snapshot, and no operations against the other form's compiled snapshot, both ways. Its second pair has the range first and no name.
  • No model had the range first before. Bookings.DuringFirst is new, with its statement, its snapshot, its twin over Npgsql's range, a 5.x snapshot in 5.x's form (ComingFrom5xTests), and a live test.

Each guard without its subject, in a copy of the commit outside the checkout:

Broken What the tests said
The starting form accepts = Started_with_equality_the_unchecked_operator_is_refused_as_the_chained_form_refuses_it and the cross-tests' Started_with_equality_the_unchecked_operator_is_refused: "Expected exception of exact type ArgumentException but no exception was thrown"
The starting form makes another declaration (the operator with a space behind it) 3 of the package's tests and 9 of the cross-tests fail: the two comparisons with the records ("expected the values to be equal"), the two stored-form tests (the keys differ), and the diffs, where the dialect refuses the operator
The method is not public Both consumer compile tests and four probe rows: CS1061 in the allowed twin. The cross-tests do not build
The method carries SK9001 Both consumer compile tests and four probe rows report SK9001. The cross-tests do not build, since that project opts into nothing
ExclusionElements<TEntity> has a public constructor The_factory_starts_the_elements_with_an_operator_of_ones_own_and_hands_out_no_other_way fails

The tests that compile against the method are tests of the feature: without the method they do not build, which is said here and not counted as a guard.

Run locally: dotnet build CodoMetis.EFCore.SchemaKit.slnx with no warning; offline, the kernel's tests (911), the PostgreSQL package's (498) and the cross-tests (33). On PostgreSQL 16 and 18, in two throwaway containers that are removed again: the cross-tests' live tests (13 each, with A_constraint_over_the_range_alone_applies_on_a_database_without_any_extension and the new A_constraint_with_the_range_first_is_migrated_to_what_EnsureCreated_builds_and_refuses_an_overlap) and PgExclusionLiveTests (60 each). Not run locally: the rest of the PostgreSQL package's live tests, the SQL Server lane, the spikes and the consumer smoke test, none of which this change touches.

🤖 Generated with Claude Code

CaffeinatedCoder and others added 3 commits November 29, 2026 12:06
…perator of one's own

PgSchema<TEntity>.WithUncheckedOperator(key, operator) returns
ExclusionElements<TEntity> and goes through Exclusions.Unchecked, so "="
is refused as the chained form refuses it. A constraint over another
library's range alone, or with that range first, has a lambda form. The
declaration is the one the records make: one key and one value.

Refs #257

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… starts the elements

The paragraph on ValueRanges no longer sends the range alone to records, the
row of what is not there yet is gone, and the guide's two rows name the form
for the first element. A 5.x snapshot with the range alone or first is held
against the starting form.

Refs #257

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…an assertion that cannot fail

Refs #257

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 29, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL area/constraints Exclusion constraints, row guards and other constraint-like objects labels Nov 29, 2026
@CaffeinatedCoder

Copy link
Copy Markdown
Owner Author

Reviewed at 873c47d by the coordinating session.

  • Read: the one new method on PgSchema<TEntity>, which goes through Exclusions.Unchecked as the chained form does, and the pages. Nothing else joins the surface, and the stored form does not move: the description's test holds a model written with the factory to the keys and values of the same model written as records.
  • Run, in a copy of the head with the method building its element without Exclusions.Unchecked: Started_with_equality_the_unchecked_operator_is_refused_as_the_chained_form_refuses_it fails, "Expected exception of exact type ArgumentException but no exception was thrown" (1 failed, 25 passed of PgExclusionDeclarationTests).
  • The design's row for WithExpression(sql, "="), which named a call that throws, is put right in passing.
  • Merges cleanly into main at 11158ac (after feat: the verifier is one oracle with the tests, and a consumer meets it #277, which also changed the README).

Nothing to change.

@CaffeinatedCoder
CaffeinatedCoder merged commit 8166333 into main Nov 29, 2026
12 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the claude/dreamy-carson-502d61 branch November 29, 2026 11:32
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/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An exclusion constraint cannot start with a range of another library: the factory has no unchecked operator

1 participant