Skip to content
Latchkey

sqitch revert: Roll Back Changes

sqitch revert runs the revert scripts to undo deployed changes, optionally back to a specific change.

revert is Sqitch rollback. Each change has a revert script; revert runs them in reverse order down to the point you specify.

What it does

sqitch revert runs the revert/*.sql script for each deployed change, newest first, down to (but not including) the --to-change target, updating the registry as it goes. Without a target it reverts every deployed change.

Common usage

Terminal
# revert back to a named change, no prompt
sqitch revert --to-change add_users -y db:pg://ci:$DB_PASSWORD@db:5432/app

# revert everything
sqitch revert -y db:pg://ci:$DB_PASSWORD@db:5432/app

Options

Flag / argWhat it does
--to-change <name>Revert down to (excluding) this change
-y, --yesSkip the interactive confirmation
<target>Target URI or named target
--modifiedRevert changes whose scripts changed since deploy

In CI

Always pass -y so revert does not stop at its confirmation prompt and hang the job. Revert depends on correct revert scripts; a revert that drops a table loses data, so treat it as recovery on disposable databases rather than a routine deploy step.

Common errors in CI

A hanging job means revert is waiting at the "Revert all changes ... [Yes]" prompt; add -y. "Change ... has not been deployed" means the --to-change target is not in the deployed set. A revert script that errors leaves the registry mid-way; fix the script and re-run to a known change.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →