rollback
Roll back one or more previously applied migrations using U scripts.
Database required: Yes
Usage
bash
# Roll back the last migration
dbsh rollback --environment local
# Roll back the last 3 migrations
dbsh rollback --environment production --count 3
# Roll back a specific version
dbsh rollback --environment production --target-version 003
# Non-interactive
dbsh rollback --environment production --yesOptions
| Option | Short | Description |
|---|---|---|
--target-version | -V | Specific version to roll back (default: last applied) |
--count | Number of recent migrations to roll back (default: 1) | |
--executed-by | -u | User performing the rollback |
Also accepts global options.
Prerequisites
Each forward migration must have a paired rollback script:
Database/Migrations/Schema/V001__CreateUsersTable.sql
Database/Migrations/Rollback/U001__Rollback_CreateUsersTable.sqlThe version must match (without the V/U prefix).
If no U script exists for a migration, rollback fails with a clear message.
Rollback order
When rolling back multiple migrations (--count or --target-version), they are undone in reverse chronological order — most recent first.
Notes
- Rollback executes the
Uscript in a transaction - The migration record is updated to
RolledBackstatus in__migration_history - The audit trail records the rollback action
- Some environments may have
allowRollback: false— check your environment config