wheels dbmigrate exec
Execute a specific database migration by version number.
Synopsis
Description
The dbmigrate exec
command allows you to run a specific migration identified by its version number, regardless of the current migration state. This is useful for applying individual migrations out of sequence during development or for special maintenance operations.
Arguments
<version>
<version>
Type: String
Required: Yes
Description: The version number of the migration to execute (e.g., 20240115123456)
Options
--env
--env
Type: String
Default:
development
Description: The environment to run the migration in
--datasource
--datasource
Type: String
Default: Application default
Description: Specify a custom datasource for the migration
--direction
--direction
Type: String
Default:
up
Values:
up
,down
Description: Direction to run the migration (up or down)
--force
--force
Type: Boolean
Default:
false
Description: Force execution even if migration is already run
--verbose
--verbose
Type: Boolean
Default:
false
Description: Display detailed output during execution
--dry-run
--dry-run
Type: Boolean
Default:
false
Description: Preview the migration without executing it
Examples
Execute a specific migration
Execute migration's down method
Force re-execution of a migration
Execute in production environment
Preview migration execution
Use Cases
Applying Hotfix Migrations
Apply a critical fix out of sequence:
Re-running Failed Migrations
When a migration partially fails:
Testing Specific Migrations
Test individual migrations during development:
Selective Migration Application
Apply only certain migrations from a set:
Important Considerations
Migration Order
Executing migrations out of order can cause issues if migrations have dependencies. Always ensure that any required preceding migrations have been run.
Version Tracking
The command updates the migration tracking table to reflect the execution status. Using --force will update the timestamp of execution.
Down Direction
When running with --direction=down, the migration must have already been executed (unless --force is used).
Best Practices
Check Dependencies: Ensure required migrations are already applied
Test First: Run in development/testing before production
Use Sparingly: Prefer normal migration flow with up/latest
Document Usage: Record when and why specific executions were done
Verify State: Check migration status before and after execution
Version Number Format
Migration versions are typically timestamps in the format:
YYYYMMDDHHmmss
(e.g., 20240115123456)Year: 2024
Month: 01
Day: 15
Hour: 12
Minute: 34
Second: 56
Notes
The migration file must exist in the migrations directory
Using --force bypasses normal safety checks
The command will fail if the migration file has syntax errors
Both up() and down() methods should be defined in the migration
Related Commands
Last updated
Was this helpful?