Skip to content

EF migration generation: Weasel model → MigrationBuilder operation translation layer #365

Description

@jeremydmiller

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

The core translation layer: walk Weasel's strongly-typed schema model and produce EF Core MigrationOperation-shaped output, the reverse of the existing MapToTable (EF → Weasel) direction in Weasel.EntityFrameworkCore/DbContextExtensions.cs.

Design

  • Lives in Weasel.EntityFrameworkCore (already references Microsoft.EntityFrameworkCore.Relational + Weasel.Core, no concrete provider).
  • Input is the provider-neutral surface (ITable, ITableColumn, ITableIndex, ForeignKeyBase) with provider-specific strategy hooks that downcast to the concrete Table types — the same pattern the SchemaComparison harness uses via customizeTables.
  • Output is an intermediate operation list that the file emitter (separate issue) renders as MigrationBuilder calls. Use raw store type strings (ColumnType) everywhere so EF's CLR type mapping is bypassed and DDL matches Weasel exactly.

Mapping table

Weasel EF operation
Table + PK CreateTable (nested columns, PrimaryKey, checks)
TableColumn (Type, AllowNulls, DefaultExpression) AddColumnOperation w/ ColumnType, IsNullable, DefaultValueSql
IsAutoNumber provider annotations (Npgsql:ValueGenerationStrategy identity, SqlServer:Identity)
Computed columns (new model from the computed-column issue) ComputedColumnSql
IndexDefinition (unique, predicate, INCLUDE) CreateIndexOperation (+ provider annotations for filter/includes)
ForeignKey (DeleteAction/UpdateAction) AddForeignKeyOperation w/ ReferentialAction (mirror mapDeleteBehavior normalization, e.g. SQL Server Restrict ≡ NoAction)
Schemas EnsureSchemaOperation
PreserveIdentifierCase correct quoting/casing of emitted names

Raw-SQL fallback strategy

Everything EF cannot model routes through Sql() using the existing WriteCreateStatement/WriteDropStatement output, so these work on day one:

  • PostgreSQL table partitioning (RANGE/LIST/HASH, managed partitions) — no Npgsql EF support (Support for table partitioning npgsql/efcore.pg#1035)
  • PL/pgSQL functions, SQL Server stored procedures and table types
  • Sequences with DefaultValueFromSequence / nextval expressions
  • Rich PG index options (gin/gist methods, CONCURRENTLYsuppressTransaction: true, tablespaces, fill factor, collation, nulls-not-distinct)

Acceptance

  • For every SchemaComparison scenario table, the translated operations describe the same schema Weasel's own DDL produces (validated end-to-end by the harness-inversion issue).
  • Deliberate design note: because Weasel authors the operations, renames emit RenameColumnOperation/RenameTableOperation instead of EF's drop+add.

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