Skip to content

feat: the SQL vocabulary, statements with no hole for a string - #42

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
feat/23-sql-vocabulary
Nov 11, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
feat/23-sql-vocabulary

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #23

Problem

Every schema object SchemaKit will create is rendered at design time into a SqlOperation, text that EF Core runs as it is. In 5.x that text was built by string concatenation with a hand-rolled Quote, and the prototype of this design dropped an index by an unqualified name. The contract needs a way to write DDL in which an unquoted name is not a mistake a reviewer has to catch, and spike B added a second rule: a statement without the provider's terminator passes every path except the generated scripts.

Change

src/CodoMetis.EFCore.SchemaKit/Sql, the first part of the contributor contract. Public, and marked [Experimental("SK9001")] until the contract freezes at rc.1.

  • Values: Identifier, TableRef, QualifiedName, SqlName, SqlOperator, SqlFragment. None has a public constructor taking text, and none converts from string.
  • SchemaSql: sql.Statement($"CREATE INDEX {name} ON {table} ({column})"). A hole takes only those values, int and long. It appends the provider's statement terminator, and refuses a statement that brings one, an empty one, and a DROP … IF EXISTS.
  • ISchemaDialect and SchemaDialect: the only place that turns text into those values. Length is checked against the model's MaxIdentifierLength, operators against the operator grammar; delimiting and the terminator are the provider's ISqlGenerationHelper, literals its type mapping.
  • SchemaScope: a closed Table | Schema | Database, for descriptors (SchemaKit: the contributor contract, so packages add schema objects instead of replacing EF services #7).
  • TableRef.Qualify(name) for objects named within a schema.

The host, one change: SchemaKitModelDiffer and SchemaKitSqlGenerator resolve the planner and the rewriters on first use instead of taking them in the constructor. The ownership check resolves both decorators while a model is being built, and a planner needs the dialect, which reads the design-time model. The test planner now takes the dialect in its constructor on purpose.

CI: an Integration (PostgreSQL 18) lane with a service container, behind the CI gate. It writes the image digest to the summary and fails when no integration test ran.

Decisions made here, for review

  • Public and experimental. The compile probes and every future contributor need these types public; SK9001 makes using them a deliberate opt-in until rc.1. The id is my choice.
  • No bool hole, unlike the prototype. How a boolean is spelled is the dialect's (true, ON, 1).
  • DROP … IF EXISTS is refused by the builder, at run time, by a check of the statement's text. CREATE … IF NOT EXISTS is not.
  • Qualification is the contributor's call, not the type's. A constraint and a trigger are legitimately named within their table, so the types cannot demand a qualified name for every kind. Each contributor's live test has to hold it.
  • E4 moves to SchemaKit: the contributor contract, so packages add schema objects instead of replacing EF services #7. E4.render-a-declaration needs the contributor base class. The slot here is E4.identifier-not-constructible.
  • The generic dialect counts characters. PostgreSQL counts bytes; its package has to override Measure (noted on PgExclusion: exclusion constraints end to end #25).

Tests

  • 162 kernel tests, on Npgsql, SQL Server and SQLite: rendering against the provider's own helper, a hostile name that cannot leave its delimiters, literals, lists, the refusals, the dialect's checks, and the widened surface tests (every contract type experimental, no constructor or conversion from text, the handler's overloads held to the list).
  • Two on a live PostgreSQL 18: one index name in two schemas. The qualified drop removes the one it names; the unqualified one removes the public schema's and leaves the one meant. The setup runs five statements as one batch, which only works if each is terminated.
  • 25 compile-probe tests against the shipping assembly (KernelProbeTests, 11 probes with an allowed twin each): a string, an object or a format in a hole, a fragment, identifier, qualified name or operator from text, the builder not constructible, the scope's missing arm and foreign case, and the contract without its opt-in. The prototype's 72 still pass.
  • Fourteen mutations, each in a scratch copy, each failed tests or probes: a string hole, a generic hole, no terminator, a public Identifier constructor, a conversion from string, no length check, no operator check, DROP IF EXISTS allowed, an own terminator allowed, an undelimited identifier, a qualified name without its schema, the planner injected (121 tests fail on the cycle), a type without the experimental mark, the scope not closed.
  • Without SCHEMAKIT_TEST_PG the integration tests go inconclusive locally and fail when CI is set; both were run.

Not covered: SQL Server and SQLite on a live server for these statements, and a generated script through dotnet ef, which spike B holds.

Built locally on SDK 11.0.100-rc.1 in a scratch copy; this PR's lanes are the run on SDK 11.0.100.

🤖 Generated with Claude Code

The first part of the contributor contract (#23), public and marked experimental
(SK9001) until the contract freezes at rc.1.

- Identifier, TableRef, QualifiedName, SqlName, SqlOperator and SqlFragment have no
  public constructor taking text and convert from none: an identifier comes from the
  dialect, which checks its length, an operator from the dialect's grammar.
- SchemaSql builds a statement from an interpolated string whose holes take only those
  values, int and long. It appends the provider's statement terminator and refuses a
  statement that brings one, an empty one, and a DROP … IF EXISTS.
- SchemaDialect delimits and terminates through the provider's ISqlGenerationHelper
  and writes literals through its type mapping; SchemaScope is a closed Table | Schema
  | Database.
- A schema-scoped object is dropped by table.Qualify(name). On a live PostgreSQL the
  unqualified form removes another schema's index, which is now a test.
- The host resolves its planner and rewriters on first use: the ownership check
  resolves the differ while a model is built, and the dialect reads the design-time
  model. Injected, the planner cycles (121 tests fail that way).

162 kernel tests on Npgsql, SQL Server and SQLite, two of them on a live PostgreSQL 18
behind a new integration lane; 25 compile-probe tests against the shipping assembly
beside the prototype's 72. Fourteen mutations each failed their tests or probes.
Built locally on SDK 11.0.100-rc.1 in a scratch copy.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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 enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQL vocabulary: Identifier, QualifiedName, SchemaSql with no hole for a string

1 participant