Skip to content
Latchkey

migrate down: Roll Back golang-migrate

migrate -path <dir> -database <url> down N reverts the last N migrations using their .down.sql files.

down is the rollback half of golang-migrate. Each migration has a paired .down.sql, and down runs them in reverse order.

What it does

migrate ... down N applies the down migrations for the last N applied versions, in reverse order. Bare down (with -all or an interactive confirm) reverts everything. It updates schema_migrations to the resulting version.

Common usage

Terminal
# revert the most recent migration
migrate -path ./migrations -database "$DATABASE_URL" down 1

# revert everything (non-interactive)
migrate -path ./migrations -database "$DATABASE_URL" down -all

Options

Arg / flagWhat it does
down [N]Revert the last N migrations
down -allRevert all migrations without an interactive prompt
-path <dir>Directory of migration files
-database <url>Connection URL

In CI

Bare down prompts for confirmation, which hangs a pipeline; always pass down N or down -all so it is non-interactive. Rollback only works if the .down.sql files are correct and reversible; a down that drops a column loses data, so treat rollbacks in CI as recovery, not routine.

Common errors in CI

"Dirty database version N. Fix and force version" appears here too if a prior run failed; run migrate force <version> first. A hanging job usually means bare down waiting for the "Are you sure" prompt; use down N or -all. "no change" means nothing was left to revert.

Related guides

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