Automatic rollback is intentionally not supported to prevent accidental data loss in production. Follow the manual steps below.
DATABASE_URL=postgres://... ./scripts/run_migrations.sh --statusCreate a SQL file that reverses the changes made by the target migration. Common patterns:
| Original operation | Rollback operation |
|---|---|
CREATE TABLE foo |
DROP TABLE foo; |
ALTER TABLE foo ADD COLUMN bar |
ALTER TABLE foo DROP COLUMN bar; |
CREATE INDEX idx_foo |
DROP INDEX idx_foo; |
CREATE EXTENSION pgcrypto |
DROP EXTENSION pgcrypto; |
psql "$DATABASE_URL" -f your_down_migration.sqlDELETE FROM schema_migrations WHERE version = '005';./scripts/run_migrations.sh --statusThe version will now appear as (pending) and will be re-applied on the
next run_migrations.sh run.
Repeat steps 1–4 in reverse order (highest version first).
Only use this in a development/staging environment where data loss is acceptable.
psql "$DATABASE_URL" -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
./scripts/run_migrations.sh