Skip to content

Spike: attribute-only EF Core migrations without a real EF model #364

Description

@jeremydmiller

Part of the EF Core migration generation epic — tracking issue #371.

De-risking spike for the whole epic: verify that a hand-written, attribute-only EF Core migration with no real EF model is a first-class citizen of the EF toolchain. Research strongly indicates yes (empty BuildTargetModel bodies are legal; the ModelSnapshot is design-time only; runtime discovery needs only the [DbContext] + [Migration] attributes), but this converts belief into verified fact before we build the generator.

What to build

A throwaway test project containing:

  1. A stub DbContext (no entities) configured for Npgsql and SqlServer, with ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning)) — required on EF Core 9+, which otherwise throws from Migrate() when the context model doesn't match the last migration.
  2. One or two hand-written Migration subclasses carrying [DbContext]/[Migration("yyyyMMddHHmmss_Name")] attributes, with Up/Down bodies using MigrationBuilder calls (including raw store types via ColumnType) and a migrationBuilder.Sql(...) block.

Verify on both Npgsql and SqlServer EF providers (EF 9 and 10)

  • dotnet ef database update applies them and records __EFMigrationsHistory rows
  • Runtime Migrate() / MigrateAsync() works (no pending-model-changes throw with the suppression in place)
  • dotnet ef migrations script --idempotent produces a correct script
  • Migration bundles (dotnet ef migrations bundle) work
  • Down() / migrating backwards works
  • A second context in the same database with its own history table location coexists cleanly (the mixed EF + Marten/Wolverine scenario)

Stretch

  • Check the SQLite EF provider: its ALTER-emulation (table rebuild) is the most model-hungry code path and may not tolerate an empty TargetModel. Outcome decides whether SQLite is in or out for v1 of the generator.

The spike code does not need to merge; the deliverable is a written summary of results on this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions