Docs/Commands/undo
OSSgenerated from cli/_parser_setup.py
dblift undo
Roll back migrations. Runs the undo script paired with each applied migration, newest first, and records the reversal in the schema history table. A migration with no paired undo script cannot be reversed.
Synopsis
$ dblift undo [--target-version VERSION]
[--show-sql] [--show-query-results]
[--tags TAGS] [--exclude-tags TAGS]
[--versions LIST] [--exclude-versions LIST]
[--placeholders K=V [K=V ...]]
[--strict] [--table TABLE]Options
FlagDescription
--tableCustom schema history table name (default: dblift_schema_history)--strictEnable strict mode - fail if any previously applied migration is missing and require migrations to be applied in strict version order--tagsExecute migrations with specified tags (comma-separated list)--exclude-tagsSkip migrations with specified tags (comma-separated list)--versionsExecute only specific versions (comma-separated list)--exclude-versionsSkip specific versions (comma-separated list)--placeholdersSQL placeholders for variable substitution in migration scripts. Format: key1=value1,key2=value2 or key1=value1 key2=value2. Can be repeated: --placeholders k1=v1 --placeholders k2=v2--db-urlDatabase URL--db-usernameDatabase username--db-passwordDatabase password--db-schemaDatabase schema--target-versionTarget version to roll back to--show-sqlShow SQL statements in command output and reports--show-query-resultsShow rows returned by SELECT statements in command output and reportsGlobal flags apply to every command: --config, --env, --scripts, --dry-run, --quiet, --log-level. See global flags.
Examples
See the reversal SQL without running it
$ dblift undo --target-version 1.0.0 --dry-run --show-sql┏━━━━━━━━━━━━━━━━━━━━━━━ DBLIFT DATABASE MIGRATION LOG ━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Timestamp: 2026-01-15 12:00:00 ┃ ┃ Dblift version: 3.9.0 ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ DBLIFT COMMAND: UNDO ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Connected to database ./app.db (SQLite) ┃ ┃ Database: ./app.db ┃ ┃ Schema: main ┃ ┃ Schema Version: 1.2.0 ┃ ┃ Database URL: sqlite:///./app.db ┃ ┃ Filtering Options: --dry-run --target-version=1.0.0 --show-sql ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ Found 2 migration(s) to undo DRY RUN: Would undo the following migrations: - V1_2_0__add_note[auth].sql - V1_1_0__users_created_at[core].sql ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SUCCESS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Command UNDO completed successfully (Execution time: 12 ms) ┃ ┃ Schema Version: 1.2.0 ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ SQL Statements: -------------------------------------------------------------------------------- -- U1_2_0__drop_note.sql ALTER TABLE users DROP COLUMN note; -- U1_1_0__drop_created_at.sql ALTER TABLE users DROP COLUMN created_at; --------------------------------------------------------------------------------
Reverse a single version
$ dblift undo --versions 1.2.0 --dry-run --show-sql┏━━━━━━━━━━━━━━━━━━━━━━━ DBLIFT DATABASE MIGRATION LOG ━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Timestamp: 2026-01-15 12:00:00 ┃ ┃ Dblift version: 3.9.0 ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ DBLIFT COMMAND: UNDO ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Connected to database ./app.db (SQLite) ┃ ┃ Database: ./app.db ┃ ┃ Schema: main ┃ ┃ Schema Version: 1.2.0 ┃ ┃ Database URL: sqlite:///./app.db ┃ ┃ Filtering Options: --dry-run --versions=1.2.0 --show-sql ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ Found 1 migration(s) to undo DRY RUN: Would undo the following migrations: - V1_2_0__add_note[auth].sql ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SUCCESS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Command UNDO completed successfully (Execution time: 12 ms) ┃ ┃ Schema Version: 1.2.0 ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ SQL Statements: -------------------------------------------------------------------------------- -- U1_2_0__drop_note.sql ALTER TABLE users DROP COLUMN note; --------------------------------------------------------------------------------
Exit codes
CodeMeaning
0Command completed successfully4A paid-edition feature was invoked without a valid licence (EXIT_LICENSE_REQUIRED)