Skip to content

Computed/generated column support (PostgreSQL + SQL Server) #363

Description

@jeremydmiller

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

Weasel does not currently model computed/generated columns for PostgreSQL or SQL Server — GeneratedAlwaysAsStored / GeneratedAsIdentity are commented out in Weasel.Postgresql/Tables/TableColumn.cs. SQLite already supports GeneratedAs(...), so this is parity work. This is also a documented gap in the EF Core schema-comparison harness (EFCORE_IMPROVEMENTS.md), since EF Core can express computed columns via HasComputedColumnSql.

This phase is pure Weasel work with no EF dependency, so it can proceed independently of the rest of the epic.

Scope

  • PostgreSQL: GENERATED ALWAYS AS (expression) STORED (PG 12+). Model VIRTUAL as well (arrives in PG 18) but gate DDL emission by server capability.
  • SQL Server: computed columns AS (expression) [PERSISTED].
  • Model: expression + stored/virtual flag on TableColumn (fluent API mirroring the existing SQLite GeneratedAs), surfaced on the provider-neutral ITableColumn where sensible.
  • Introspection: read generated-column metadata in FetchExisting (pg_attribute.attgenerated on PostgreSQL, sys.computed_columns on SQL Server) so the "actual" model captures it.
  • Delta detection: participate in TableDelta comparison (expression normalization will be needed — the catalogs return normalized expressions, similar to the existing index/check DDL canonicalization).
  • EF Core mapping: MapToTable in Weasel.EntityFrameworkCore translates HasComputedColumnSql → the new Weasel computed-column model.
  • Harness: add a computed-column scenario to the SchemaComparison tests for PostgreSQL and SQL Server, and remove the "known gap" entry from EFCORE_IMPROVEMENTS.md.

Acceptance

  • Tables with computed columns round-trip: create via Weasel → delta detection reports None.
  • EF DbContext with HasComputedColumnSql maps to Weasel and passes the dual-schema comparison harness on both providers.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions