Skip to content

sqlgen: opt-in emission of recreate DDL for UNSAFE changes (MV recreate, engine/ORDER BY changes) #90

Description

@orian

Symptom

Unsafe changes (engine swap, ORDER/PARTITION/SAMPLE BY, column storage-class switches, MV query recreation) are correctly reported via unsafeReasons (internal/loader/hcl/sqlgen.go:1101-1144) and rendered as -- UNSAFE: comments — but there is no opt-in way to actually generate the recreate DDL. For MVs the DROP+CREATE is explicitly not emitted (sqlgen.go:128-134); for storage-class column changes the MODIFY is skipped (sqlgen.go:733-734).

Impact

The operator is told "this requires recreating the table/view" and then has to hand-write the DROP+CREATE (plus data backfill) themselves. The tool knows both sides of the diff and could generate the statements.

Fix direction

Add an opt-in flag (e.g. diff -sql -emit-unsafe) that emits the recreate sequence for unsafe changes, clearly marked, instead of only the advisory comment. Default behavior unchanged.

Found in the 2026-07-02 deep-dive audit (docs/plans/2026-07-02-deep-dive-improvement-areas.md, B6).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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