Skip to content

fix: Overlaps takes a range or a multirange, and a plain array no longer compiles - #162

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
claude/104-overlaps-ranges-6151c2
Nov 16, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
claude/104-overlaps-ranges-6151c2

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #104

Problem

PgSchema<T>.Overlaps over an array or a List<T> took any element type. A consumer who wrote

pg.Exclusion(pg.Overlaps(x => x.Tags), name: "ex_tags")   // Tags is an int[]

got a declaration that compiled and scaffolded CREATE EXTENSION IF NOT EXISTS btree_gist; plus the constraint, and a migration that failed at apply with 42704: data type integer[] has no default operator class for access method "gist". The rule of the API is that a declaration PostgreSQL would reject does not compile.

Change

Option 1 of #104, as decided:

  • src/CodoMetis.EFCore.SchemaKit.PostgreSQL/PgSchema.cs: the array and list overloads of Overlaps, on PgSchema<T>, ExclusionDraft<T> and ExclusionElements<T>, take NpgsqlRange<T>[] and List<NpgsqlRange<T>>, which is what Npgsql maps to a multirange. The parameter is multirange. A plain array or list no longer compiles. WithUncheckedOperator stays the way to && over an array for a database that brings its own operator class (intarray).
  • README.md: Overlaps is on a range or a multirange, and the known defect is gone.
  • design/schemakit-api.md, P3: the overloads as they are now, and why the plain array is out.
  • CHANGELOG.md: the preview's exclusion-constraint line says what Overlaps takes.

No 5.x fixture, snapshot or stored form is touched: the overloads only build KeyTarget.Column elements, as before. Every sample in the docs and the smoke test uses a range.

Tests

  • ConsumerCompileTests.Overlaps_over_a_plain_array_does_not_compile (int[] and List<int>): compiled against the shipped assemblies, each of the three places an element is added (pg.Overlaps, after Equal, after another Overlaps) is refused with CS0411. With PgSchema.cs reverted to main both rows fail (0 diagnostics in place of 3); with the change they pass.
  • ConsumerCompileTests.Overlaps_over_a_multirange_compiles (NpgsqlRange<DateOnly>[] and List<NpgsqlRange<DateOnly>>): the allowed twin, the same three places, no diagnostic.
  • PgExclusionLiveTests.A_constraint_on_a_multirange_refuses_overlapping_rows: a model with pg.Equal(x => x.WorkerId).Overlaps(x => x.Shifts) (an array of ranges) and pg.Overlaps(x => x.Leave) (a list) is created by a first migration; the catalog holds both columns as datemultirange and both constraints, and a write whose ranges overlap anywhere in the multirange is refused with 23P01 by the constraint it breaks, while another worker and adjacent ranges pass. It runs in CI on PostgreSQL 16 and 18; no local server was started for it. The create script was checked offline to write both columns as datemultirange.
  • Offline: the PostgreSQL tests (180, documentation included) and the kernel's (723) pass; the solution builds with no warning.

🤖 Generated with Claude Code

…ger compiles

The array and list overloads of Overlaps took any element type. Over an
int[] the declaration compiled, scaffolded, and failed at apply with
42704: GiST has no operator class for a plain array. They now take
NpgsqlRange<T>[] and List<NpgsqlRange<T>>, which is what Npgsql maps to a
multirange.

ConsumerCompileTests holds both sides against the shipped assemblies; a
live row creates a constraint over an array and a list of ranges and
refuses the overlapping writes.

Closes #104

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 16, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working 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 16, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit f35049d into main Nov 16, 2026
11 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the claude/104-overlaps-ranges-6151c2 branch November 16, 2026 22: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 bug Something isn't working 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.

Overlaps over a plain array compiles and fails at apply: no GiST operator class (42704)

1 participant