Skip to content

Spike D: SqlOperations in idempotent scripts and bundles - #146

Merged
CaffeinatedCoder merged 7 commits into
mainfrom
spike/d-scripts-and-bundles
Nov 16, 2026
Merged

CaffeinatedCoder merged 7 commits into
mainfrom
spike/d-scripts-and-bundles

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Closes #19

Problem

Every object SchemaKit creates reaches a migration as a SqlOperation rendered at design time (plan, decision 4). Whether one that suppresses the transaction, and a trigger, survive migrations script --idempotent applied twice and a migrations bundle run twice was not measured, on PostgreSQL or on SQL Server. concurrently: of preview.2 (#27) and the row guard's trigger (#47) rest on the answer. Point 4 of #115 asks a second thing nobody had measured: what EF Core does with an annotation on a SqlOperation.

Change

spikes/D.ScriptsAndBundles, in the manner of spikes B and E. Nothing under src/ changes.

  • consumer/ is a project a consumer could write. Kit.cs is a contributor against the kernel's public contract, so its statements reach the migration through the planner and SchemaKitModelDiffer. Program.cs is the judge: it reads the catalog and applies a script the way psql and sqlcmd apply one.
  • run.sh packs both packages, copies the consumer out of the repository once for each provider and statement, drives dotnet ef, and applies each script and each bundle twice in a database of its own. It holds the table: a cell that answers otherwise fails the run. Where psql or sqlcmd can be reached, on PATH or in the server's container, every script goes through the tool itself as well.
  • README.md has both questions, how to run it, the tables, and each error with the SQL that caused it.
  • CLAUDE.md lists the spike and its command; the plan's row D says what was measured.

CI's spikes lane runs it with no change to the workflow: run.sh reads spike E's connection strings where its own are not set.

What it measured

EF Core 11.0.0-rc.3, on PostgreSQL 16 and 18 and SQL Server 2022, on a developer's machine and in CI, with the same answer in both places. A bundle carries the statements of the question. A script does not carry two of them:

Statement Path First run Second run
PostgreSQL: CREATE INDEX CONCURRENTLY, transaction suppressed migrations script --idempotent 25001, refused inside the DO block. psql goes on and exits 0: the migration is recorded, the index is missing No error, the index stays missing
SQL Server: CREATE TRIGGER migrations script 111: a migration is one batch, and nothing of it is applied not applicable
migrations script --idempotent 156: the same The same error

PostgreSQL's trigger with its function applies on every path, and the second run changes nothing. So does a statement with the transaction suppressed on SQL Server: ALTER DATABASE CURRENT SET ALLOW_SNAPSHOT_ISOLATION ON, which the server refuses inside a transaction, applies on every path suppressed and fails on every path without. On SQL Server the trigger survives every path inside EXEC(N'…'), which the contract can write for a statement on one line only; with line breaks what it writes is not valid T-SQL and fails in the bundle too. The full table is in the README and on #19.

The annotation: migrations add writes it as .Annotation(…) on migrationBuilder.Sql(…), in Up and in Down, and the generator inside SchemaKit's decorator receives it at migrations script, at --idempotent and when a bundle applies the migration, on Npgsql, SQL Server and SQLite. The answer is on #115.

The spike builds no refusal. What has to be built is #155 (PostgreSQL) and #156 (SQL Server).

Tests

The spike is the measurement, so what holds it is how it is judged:

  • By the server. After each run the judge reads the catalog: an index has to be valid, a trigger has to accept one row and refuse another with its own error. The second run is compared with the first by an identity a recreation changes, and the judge shows it changing for each kind of object.
  • Shown to fail. The same check that says "applies" sees the index and the trigger missing in the failing cells, and the control for the suppression on SQL Server fails on every path.
  • Against the tools. psql 16.15 and 18.6 and sqlcmd 18.7 left the object, the table and the history the judge's way left, for every consumer, with their defaults and with the stop switch. In CI psql 18.6 does the same; the runner has no sqlcmd.
  • Twice. run.sh passes locally on all three servers and in CI's spikes lane.

After the analysis of this PR

An independent analysis reproduced every cell and found defects in the harness and in the wording. No published cell changed. Each was reproduced before it was fixed:

  • A database that could not be created made its cells vanish, and the run still ended with "every cell answered". Now each path has a failing row. Shown: with Create made to throw for every database after the first, the run fails with one row for each path.
  • A run with no server named claimed every cell. Off CI it now ends with NOT MEASURED: … and claims only what was measured.
  • CREATE INDEX … WITH (ONLINE = ON) never tested suppression: SQL Server builds it inside a transaction too. The ALTER DATABASE rows and their control are new, and An idempotent script cannot carry a statement with the transaction suppressed on PostgreSQL: the migration is recorded without its index #155 no longer rests on the online index.
  • A SQL Server index was told apart by object_id and index_id, which a drop and create keeps. It is now the rowset's id.
  • The annotation checks: five annotations, not four, and the object's name is now checked where the generator receives it. The snapshot and the designer file have to exist for "neither holds it" to pass.
  • The tool comparison can now be run as the README describes it: the containers' own clients are reached through three variables, and the README says how a script goes in (standard input, without the byte order mark for sqlcmd).
  • New facts, written down as measured: a trigger created through sqlcmd's defaults has uses_quoted_identifier 0, and 1 from a bundle; and on SQL Server a statement that fails at run time does not end its batch, so the script records the migration with that statement never run.

One defect of the script's own was found before that and fixed: it read a bundle's exit code from the wrong command.

🤖 Generated with Claude Code

…r and its script

For #19 and point 4 of #115. The consumer writes a contributor against the kernel's
public contract, so its statements reach a migration through SchemaKit's planner and
differ; run.sh packs the packages, drives dotnet ef from outside the repository and
judges every run by the catalog. The table is not measured yet.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 16, 2026
@CaffeinatedCoder CaffeinatedCoder added tests Adds or changes tests only (harnesses, parity suites); no library code package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL package/sqlserver Affects CodoMetis.EFCore.SchemaKit.SqlServer area/migrations The differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiring labels Nov 16, 2026
CaffeinatedCoder and others added 5 commits November 16, 2026 13:59
…r's cells from CI

The judge reports the server's own words, the table's state is part of each cell, and
a body with line breaks through EXEC is measured as well.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
… and a bundle's exit code

The judge's way of applying a script is held against the provider's own client where
the machine has one. A trigger's body as the catalog keeps it is compared across the
paths. A bundle's exit code was read from the wrong command; a failing bundle is now
reported as one.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The table is measured on PostgreSQL 16 and 18 and SQL Server 2022, on a developer's
machine and in CI, and held by run.sh. CLAUDE.md lists the spike and its command; the
plan's row D says what was measured.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…carries on SQL Server

A database that cannot be created is a failing row for each path, where before the
cells went missing from a run that then reported every cell. A run with a server
nobody named says NOT MEASURED in its last line. An index on SQL Server is told apart
by its rowset's id, and every identity is shown to change when the object is dropped
and created again. The annotation checks hold all five, the object's among them, and
the snapshot and the designer file have to be there.

SQL Server's online index is built inside a transaction too, so it never said whether
the suppression arrives. ALTER DATABASE … ALLOW_SNAPSHOT_ISOLATION, which the server
refuses in a transaction, does: suppressed it applies on every path, and the control
without the suppression fails on every path.

The provider's own client is reached on PATH or in the server's container, and
uses_quoted_identifier of a trigger sqlcmd created is held beside the cell.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@CaffeinatedCoder
CaffeinatedCoder merged commit bae199d into main Nov 16, 2026
10 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the spike/d-scripts-and-bundles branch November 16, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/migrations The differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiring package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL package/sqlserver Affects CodoMetis.EFCore.SchemaKit.SqlServer tests Adds or changes tests only (harnesses, parity suites); no library code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spike D: SqlOperations in idempotent scripts and bundles

1 participant