Roll back a bad migration: code and database together
Originally published on gregale.dev . I build Gregale, so read this as a vendor's page. Competitor details come from each vendor's own docs, linked in the post. This post was written with AI assistance. To undo a bad migration, you have to roll back two things: the code and the database. Most platforms roll back only the code; the database is a separate service with its own backups, and putting…
When rolling back a bad migration, both the code and the database must be restored. Most platforms only restore the code, while the database requires manual intervention. Gregale simplifies this process with a single command, gregale rollback --restore-databases, which restores the managed PostgreSQL database to the state before the migration and moves the app to the restored database simultaneously. The original database with all its data remains untouched.
Rolling back only the code can lead to issues if the migration dropped or renamed a column, changed data types, or modified data. To avoid this, Gregale verifies that rolling back to a release older than the migration is not possible unless the user acknowledges it.
An automatic rollback never goes further back than the migration. If undoing a failing release would expose users to older code, Gregale notifies you so you can choose between fixing the issue or restoring the database.
To perform a rollback, run gregale rollback my-api --to v41 --restore-databases. Gregale names the migrations it undoes and the restore point, guides you through the process step-by-step, and handles any failures gracefully. Writes after the restore point are preserved in the original database, allowing you to manually compare and move data if necessary. A short outage is expected during the switch, typically under a minute.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to