Skip to content

Praefect: add sql-migrate-down subcommand

Jacob Vosmaer requested to merge jv-sql-down-migrations into master

Fixes #2371 (closed)

We want to be able to roll back SQL migrations. This should be rare, because it tends to destroy data. But we want to be able to do it.

The library we use for sql migrations (github.com/rubenv/sql-migrate) uses a different way to specify rollbacks, compared to Rails / ActiveRecord. With ActiveRecord you specify the ID of the migration you want to end up at. With sql-migrate, we can only pass in a maximum number of steps down we are willing to take.

I like the ActiveRecord approach better but I did not see a good and easy way to implement it on top of sql-migrate. The solution in this MR is to just reflect how sql-migrate works on the inside.

As described in the doc, the workflow is: pick number of migrations to roll back, do dry run and verify output, if OK re-run with -f and the rollback happens.

Edited by GitLab Release Tools Bot

Merge request reports