Skip to content

test: no package here replaces EF Core's model differ or migrations SQL generator - #337

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
test/334-migration-service-ownership
Oct 19, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
test/334-migration-service-ownership

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #334

Problem

EF Core resolves IMigrationsModelDiffer and IMigrationsSqlGenerator as single services. When two packages replace one, the last registration wins and the other's migration DDL disappears without an error. From 11.0.0 on, CodoMetis.EFCore.SchemaKit owns both in the CodoMetis family. The EF packages here touch neither today, but nothing kept it that way.

Change

  • test/CodoMetis.ValueRanges.Conventions.Tests/MigrationServiceOwnershipConventionTests.cs, two tests over every packable project under src/ (discovered, so a new EF satellite is covered with no edit):
    • reflection: no type in a shipping assembly that references Microsoft.EntityFrameworkCore.Relational implements either service (EF's and Npgsql's base generators implement the interfaces, so deriving from them counts too). Floor: at least two EF assemblies found.
    • source scan (Roslyn, like EngineDispatchConventionTests): no code reference to IMigrationsModelDiffer, MigrationsModelDiffer, IMigrationsSqlGenerator, MigrationsSqlGenerator or NpgsqlMigrationsSqlGenerator under src/ (outside obj//bin/). That catches ReplaceService<…>, TryAdd<…>, ServiceDescriptor over typeof(…), base lists and using aliases; string literals naming them are flagged too. Comments and XML docs are trivia and are not read. Floor: the scan must see at least one TryAdd/ReplaceService call, so it is reading the files that register services.
  • AGENTS.md: a Critical Rules entry. A migration-aware feature goes into SchemaKit or plugs into its contract, never into a replacement of those two services here.

Not added to test/oracles/: this is a convention over the source, like EngineDispatchConventionTests, not a sweep against an independent answer. Seeds must name a registered oracle.

Tests

Seeded in a scratch copy of the tree (verify-the-guard):

  • coreOptionsBuilder.ReplaceService<IMigrationsSqlGenerator, ValueRangesMigrationsSqlGenerator>() in UseValueRanges, plus that class deriving from NpgsqlMigrationsSqlGenerator: both tests fail, naming the type (… ValueRangesMigrationsSqlGenerator implements IMigrationsSqlGenerator) and both source lines.
  • services.Replace(ServiceDescriptor.Scoped(typeof(IMigrationsModelDiffer), …)) in the NodaTime EF satellite, with a comment naming both services: the source test fails on that line only. The comment is not flagged.
  • The registrations' TryAdd< renamed away: the floor fails (Scanned 128 source files under src/ and found 0 TryAdd/ReplaceService calls).

On the unchanged tree, the full conventions project passes (406/406, .NET 11 RC2 SDK).

🤖 Generated with Claude Code

…QL generator

EF Core resolves IMigrationsModelDiffer and IMigrationsSqlGenerator as single
services, so two packages replacing one silently lose the other's DDL. From
11.0.0 on CodoMetis.EFCore.SchemaKit owns both. MigrationServiceOwnershipConventionTests
fails on a shipping EF type implementing either and on any code reference to
them under src/ (ReplaceService, TryAdd, ServiceDescriptor, a base list), with
floors on the assemblies and registrations it finds. AGENTS.md carries the rule.

Closes #334

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Oct 19, 2026
@CaffeinatedCoder CaffeinatedCoder added tests Adds or changes tests only (oracles, harnesses); no library code package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime labels Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime tests Adds or changes tests only (oracles, harnesses); no library code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Never replace EF Core's model differ or migrations SQL generator: a convention test and an AGENTS.md rule

1 participant