wheels db rollback
Rollback database migrations to a previous state.
Synopsis
Description
The wheels db rollback
command reverses previously applied migrations by running their down
methods. You can rollback a specific number of migrations or to a specific version.
Options
--steps=
Number of migrations to rollback. Defaults to 1.
--target=
Rollback to a specific migration version.
--force
Skip the confirmation prompt.
Examples
Basic Usage
Rollback the last migration:
Rollback Multiple Migrations
Rollback the last 3 migrations:
Rollback to Specific Version
Rollback to a specific point in time:
Force Rollback
Skip confirmation:
How It Works
Identifies Migrations: Determines which migrations to rollback
Confirmation: Asks for confirmation (unless --force)
Executes Down Methods: Runs the
down()
method of each migration in reverse orderUpdates Version: Updates the database version tracking
Important Considerations
Data Loss Warning
Rollbacks can result in data loss if migrations:
Drop tables
Remove columns
Delete records
Always backup before rolling back:
Migration Requirements
For rollback to work, migrations must:
Have a properly implemented
down()
methodBe reversible (some operations can't be undone)
Example migration with down method:
Common Scenarios
Development Corrections
Made a mistake in the last migration:
Feature Rollback
Remove a feature and its database changes:
Testing Migrations
Test that migrations are reversible:
Troubleshooting
"No down method"
If you see this error:
The migration doesn't have a
down()
methodAdd the method to make it reversible
Or use
wheels db reset
if in development
"Cannot rollback"
Some operations can't be reversed:
Data deletions (unless backed up in migration)
Complex transformations
External system changes
Rollback Fails
If rollback fails partway:
Check error message for specific issue
Fix the migration's down method
Manually correct database if needed
Update migration tracking table
Best Practices
Always implement down methods in migrations
Test rollbacks in development before production
Backup before rollback in production
Document irreversible changes in migrations
Use transactions in complex rollbacks
Related Commands
wheels db status
- Check current migration statewheels dbmigrate down
- Similar single rollbackwheels db reset
- Full database resetwheels db dump
- Backup before rollback
Last updated
Was this helpful?