Skip to content

feat: the kernel host, UseSchemaKit() with the differ and generator decorators and the wiring guards - #40

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
feat/21-kernel-host
Nov 11, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
feat/21-kernel-host

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #21

Problem

SchemaKit had a design, a prototype and two passed spikes, and no shipping code. Everything else in preview.1 (declarations, the planner, exclusion constraints) needs a host that puts SchemaKit's operations into every path that turns a model into DDL, and that fails loudly when it is missing or displaced.

Change

src/CodoMetis.EFCore.SchemaKit, the kernel's first content:

  • UseSchemaKit() (two overloads) and AddEntityFrameworkSchemaKit() for UseInternalServiceProvider. That is the whole public surface.
  • SchemaKitModelDiffer and SchemaKitSqlGenerator, decorators around whatever the context would have had. InnerServices finds it by replaying the other extensions' ApplyServices into a scratch collection, so no EF-internal type is named.
  • Three parts keep SchemaKit outermost, as spike A measured: the ReplaceService entry taken over (an earlier replacement becomes the inner), a registration of its own in ApplyServices, and the ownership checks.
  • SchemaKitWiringConvention, at model creation: resolves both services and throws unless the outermost is SchemaKit's, refuses an assembly that still carries the 5.x design-time services reference, and stamps the model (CodoMetis:SchemaKit). SchemaKitModelStamp.Require is what a declaration API will call first.
  • The host knows nothing of declarations. It splices what an internal ISchemaOperationPlanner returns before and after the inner differ's operations; HasDifferences runs the same plan. IMigrationOperationRewriters (for operations 5.x scaffolded, Legacy replay: migrations scaffolded by 5.x apply to a fresh database #28) run before the inner generator, which gets the whole list in one call.

Also: a solution file, a Test lane behind the CI gate, Dependabot entries, and the repository's documents (CLAUDE.md gets a section on the host; the plan's 3.2 and 3.3 follow what was built).

Decisions made here, for review

Tests

111 tests on Npgsql, SQL Server and SQLite; no database but SQLite.

  • WiringConditionTests: spike A's 21 conditions against the real host.
  • OperationOrderTests: creates after and drops before the inner operations, the inner list untouched, HasDifferences for a change only SchemaKit can see (the inner differ reports none), no planner, the rewriter in place and in order.
  • DesignTimeTests: EF Core's own DesignTimeServicesBuilder over a context with nothing but UseSchemaKit(): the design-time differ is the context's, a scaffolded migration creates the index after its table and drops it before, the snapshot records declaration and stamp, and without UseSchemaKit() scaffolding fails at the declaration.
  • SqliteEndToEndTests: EnsureCreated(), judged by sqlite_master.
  • InternalApiConventionTests, PublicSurfaceTests, LegacyPackageGuardTests.

Thirteen mutations of the host, each in a scratch copy, each failed its tests: no resolve-time check (C20, C21), no own registration (C07, C08, C21), no ReplaceService take-over (C05, C09, C16, C19), stamp not required (C03 and the design-time refusal), Validate without the ownership check (C06), the earlier replacement ignored (C05, C19), HasDifferences delegated to the inner differ, the plan spliced in the wrong order, the generator skipping rewriters, a shipping file disabling EF1001, a public type leaked, the legacy guard matching a namespace, the stamp never written.

Not covered here: EnsureCreated() on PostgreSQL and SQL Server (their lanes are #5), and the packed package from a consumer outside the repository, which spike B holds with its own kit until #34 moves it onto this package.

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

…ecorators and the wiring guards

The first shipping code (#21). UseSchemaKit() is the whole registration: no .targets,
no design-time services reference.

- SchemaKitModelDiffer and SchemaKitSqlGenerator decorate whatever the context would
  have had, found by replaying the other extensions' ApplyServices. No EF-internal
  type is named under src/; EF1001 is an error there and InternalApiConventionTests
  holds that nothing switches it off.
- Three parts keep SchemaKit outermost, as spike A measured: the ReplaceService entry
  taken over (an earlier replacement becomes the inner), a registration of its own,
  and the ownership checks (Validate at construction, a model-initialized convention
  at model build).
- The convention stamps the model; SchemaKitModelStamp.Require is what a declaration
  API calls first. It also refuses an assembly that still carries the 5.x
  design-time services reference.
- The host knows nothing of declarations: it splices what an internal
  ISchemaOperationPlanner returns around the inner differ's operations, and
  HasDifferences runs the same plan. Rewriters for 5.x operations run before the
  inner generator, which gets the whole list in one call.
- Public surface: UseSchemaKit() (two overloads) and AddEntityFrameworkSchemaKit().
  PublicSurfaceTests holds it to that.

111 tests on Npgsql, SQL Server and SQLite: the spike's conditions against the real
host, operation order, EF Core's design-time composition in process, EnsureCreated()
on SQLite judged by the catalog. Thirteen mutations of the host each failed their
tests. 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.

Kernel host: UseSchemaKit, the differ and generator decorators

1 participant