wheels dbmigrate down
Rollback the last executed database migration.
Synopsis
Description
The dbmigrate down
command reverses the last executed migration by running its down()
method. This is useful for undoing database changes when issues are discovered or when you need to modify a migration. The command ensures safe rollback of schema changes while maintaining database integrity.
Options
--env
--env
Type: String
Default:
development
Description: The environment to rollback the migration in
--datasource
--datasource
Type: String
Default: Application default
Description: Specify a custom datasource for the rollback
--verbose
--verbose
Type: Boolean
Default:
false
Description: Display detailed output during rollback
--force
--force
Type: Boolean
Default:
false
Description: Force rollback even if there are warnings
--dry-run
--dry-run
Type: Boolean
Default:
false
Description: Preview the rollback without executing it
Examples
Rollback the last migration
Rollback in production with confirmation
Preview rollback without executing
Force rollback with custom datasource
Use Cases
Fixing Migration Errors
When a migration contains errors or needs modification:
Development Iteration
During development when refining migrations:
Emergency Production Rollback
When a production migration causes issues:
Important Considerations
Data Loss Warning
Rolling back migrations that drop columns or tables will result in data loss. Always ensure you have backups before rolling back destructive migrations.
Down Method Requirements
For a migration to be rolled back, it must have a properly implemented down()
method that reverses the changes made in the up()
method.
Migration Dependencies
Be cautious when rolling back migrations that other migrations depend on. This can break the migration chain.
Best Practices
Always implement down() methods: Even if you think you'll never need to rollback
Test rollbacks: In development, always test that your down() method works correctly
Backup before rollback: Especially in production environments
Document destructive operations: Clearly indicate when rollbacks will cause data loss
Notes
Only the last executed migration can be rolled back with this command
To rollback multiple migrations, run the command multiple times
The migration version is removed from the database tracking table upon successful rollback
Some operations (like dropping columns with data) cannot be fully reversed
Related Commands
Last updated
Was this helpful?