Docs/Concepts/Undo model
OSS

Undo Model

DBLift does not guess how to reverse a migration. You write the reversal yourself as a matching U file, and undo runs those files in reverse order until it reaches the version you asked for.

Undo files pair with migrations

An undo file takes the same version as the migration it reverses, with a U prefix instead of V. The description is free text — describe the reversal, not the original change.

sql
-- V1_0_1__add_email_column.sql (forward) ALTER TABLE users ADD COLUMN email VARCHAR(255); -- U1_0_1__remove_email_column.sql (reverse) ALTER TABLE users DROP COLUMN email;

dblift info shows which applied migrations have a matching undo file and which do not — check it before you need one.

Rolling back

Preview the rollback SQL first:

dblift undo --dry-run --show-sql

Roll back everything applied after version 1.0.0:

dblift undo --target-version=1.0.0

--target-version names the version you want to end up at, not the one to remove. Use --target-version=0 to roll back everything. Any other target must be a script version, or an applied version whose file was deleted. undo takes the migration lock, the same as migrate.

Undo files are written by hand

There is no generator for undo SQL. Write the U file yourself, review it, and commit it next to the migration. undo, info, and a later migrate run that file as written.

Undo restores structure, not data

Dropping a column reverses a column addition, but the values that column held are gone. For anything destructive, the undo file is a way back to the previous schema — not a substitute for a backup, and not a way to recover rows.

Better still, avoid needing it: on Enterprise, plan and preflight propose a zero-downtime rewrite for dangerous DDL, so the risky change can be split into safe phases before it ever reaches production.

On this page