ReviewOS

stacks/bun-query-builder

Reversible migration rollback (generate + run down/inverse DDL)

#1048
Closed glennmichael123 opened this 2 months ago ·
2 months ago

Summary

migrateRollback only deletes rows from the migrations table and unlinks the file, then prints "run migrate:fresh to actually reverse schema" — no down/reverse DDL is generated or executed. Since migrate-generate already diffs models→DDL, generating inverse DDL (DROP TABLE / DROP COLUMN / reverse ALTER) for true rollback is the natural extension.

Effort: M (diff infra exists in src/migrations.ts). Location: src/actions/migrate-rollback.ts. High value — data-safe rollback is a core ORM expectation. Found via internal code audit.

9 days ago

Done in edb2f6c. migrateRollback now actually reverses schema: it derives 'down' DDL from each migration's forward SQL and runs it before removing the record (failure leaves the record intact). Inverts CREATE TABLE → DROP TABLE, ALTER TABLE ADD COLUMN → DROP COLUMN, CREATE [UNIQUE] INDEX → DROP INDEX (dialect-aware), in reverse order; non-invertible statements (data/complex DDL) are skipped and reported. reverseSchema: false keeps the legacy record-only behaviour. Exposed deriveDownStatements/splitSqlStatements with unit tests; full suite green.

Sign in to comment on this issue.