Repository navigation
Description
Built 2026-11-11 in #40. The three guards are in the kernel: SchemaKitModelStamp.Require at the declaration, Validate at context construction plus the resolve-time check in SchemaKitWiringConvention, and LegacyPackageGuard. One change from the plan: the 5.x guard looks for the DesignTimeServicesReferenceAttribute the 5.x .targets inject into the consuming assembly (the context's and the entry assembly), not for a loaded EFCore.ComplexIndexes assembly. The attribute is what would put the 5.x differ in front at design time. What is left of this issue: the messages in the docs, and the guard for a foreign-provider declaration (#22).
Measured 2026-11-11 (spikes A and B, #16 and #17). The stamp refuses a missing UseSchemaKit() at the declaration on every design-time path, also when only the design-time factory forgets it. Validate refuses a later service-only ReplaceService when the context is constructed; the resolve-time check catches what the options do not show. A compiled model without UseSchemaKit() is not a silent case for EnsureCreated() and Migrate(): EF builds the design-time model from OnModelCreating, and the declaration throws. Still silent, and the verifier's to answer: a user's own IDesignTimeServices differ, a model cache shared between options with and without the kit, and a host with no SchemaKit applying 5.x operations.
Rewritten by the 2026-11-11 decisions (plan, section 3.2). SchemaKit decorates the differ and the generator, so a package that replaced either before UseSchemaKit() becomes the inner service and keeps working. Three guards replace the startup check: a model-initialized stamp without which DeclarePostgres throws; a resolve-time check that the outermost differ and generator are SchemaKit's when the model is built; and a refusal when the EFCore.ComplexIndexes packages are still loaded. The design-time half is dropped: no simulation proves who owns the design-time collection. What no plugin can guard (a compiled model without UseSchemaKit(), a user's own IDesignTimeServices) is documented and answered by the catalog verifier.
Problem
When another package calls ReplaceService<IMigrationsModelDiffer, …> or ReplaceService<IMigrationsSqlGenerator, …> after SchemaKit's registration, EF Core uses that package's service, and every SchemaKit declaration disappears from migrations without an error. EFCore.ComplexIndexes 5.x has the same exposure today.
Change
When the two services are first resolved, at runtime and at design time, check that the resolved differ and SQL generator are SchemaKit's. If they aren't, throw, naming the type that replaced them and pointing to the plugin contract (#7).
Cover runtime ReplaceService, registration through design-time IDesignTimeServices, and a provider that registers its own after ours.
Tests
A context that replaces each service after SchemaKit's registration throws at the first migrations operation, with the replacing type's name; one test per entry point (runtime, design time). Remove the check and show that migrations add then loses the declaration silently.
Not covered
A package that replaced the services before SchemaKit loses to SchemaKit's replacement, and the check can't see it. The README says so. The answer there is the other package's own guard: CodoMetis packages never replace either service (CodoMetis.ValueRanges enforces this with a convention test, CaffeinatedCoder/CodoMetis.ValueRanges#334).
Activity
[-]SchemaKit: fail at startup when another package has replaced the model differ or the migrations SQL generator[/-][+]SchemaKit: the wiring guards, so a missing or displaced UseSchemaKit() fails loudly[/+]