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
# revert the most recent migration
migrate -path ./migrations -database "$DATABASE_URL" down 1
# revert everything (non-interactive)
migrate -path ./migrations -database "$DATABASE_URL" down -allOptions
| Arg / flag | What it does |
|---|---|
| down [N] | Revert the last N migrations |
| down -all | Revert 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.