Repository navigation
fix: Overlaps takes a range or a multirange, and a plain array no longer compiles - #162
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #104
Problem
PgSchema<T>.Overlapsover an array or aList<T>took any element type. A consumer who wrotegot a declaration that compiled and scaffolded
CREATE EXTENSION IF NOT EXISTS btree_gist;plus the constraint, and a migration that failed at apply with42704: 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 ofOverlaps, onPgSchema<T>,ExclusionDraft<T>andExclusionElements<T>, takeNpgsqlRange<T>[]andList<NpgsqlRange<T>>, which is what Npgsql maps to a multirange. The parameter ismultirange. A plain array or list no longer compiles.WithUncheckedOperatorstays the way to&&over an array for a database that brings its own operator class (intarray).README.md:Overlapsis 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 whatOverlapstakes.No 5.x fixture, snapshot or stored form is touched: the overloads only build
KeyTarget.Columnelements, 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[]andList<int>): compiled against the shipped assemblies, each of the three places an element is added (pg.Overlaps, afterEqual, after anotherOverlaps) is refused withCS0411. WithPgSchema.csreverted tomainboth rows fail (0 diagnostics in place of 3); with the change they pass.ConsumerCompileTests.Overlaps_over_a_multirange_compiles(NpgsqlRange<DateOnly>[]andList<NpgsqlRange<DateOnly>>): the allowed twin, the same three places, no diagnostic.PgExclusionLiveTests.A_constraint_on_a_multirange_refuses_overlapping_rows: a model withpg.Equal(x => x.WorkerId).Overlaps(x => x.Shifts)(an array of ranges) andpg.Overlaps(x => x.Leave)(a list) is created by a first migration; the catalog holds both columns asdatemultirangeand 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 asdatemultirange.🤖 Generated with Claude Code