Skip to content

Command Line Tools

dbmigrate exec

Execute a specific database migration by version number.

Terminal window
wheels dbmigrate exec version=<version>

Alias: wheels db exec

The dbmigrate exec command allows you to migrate to a specific version identified by its version number, regardless of the current migration state. This is useful for moving to any specific point in your migration history.

ParameterTypeRequiredDescription
versionstringYesVersion to migrate to
Terminal window
wheels dbmigrate exec version=20240115123456

Migrate to version 0 (revert all migrations)

Section titled “Migrate to version 0 (revert all migrations)”
Terminal window
wheels dbmigrate exec version=0

Move to any point in migration history:

Terminal window
# Check current status
wheels dbmigrate info
# Migrate to specific version
wheels dbmigrate exec version=20240115123456

Move to an earlier migration state:

Terminal window
# Check migration history
wheels dbmigrate info
# Go back to specific version
wheels dbmigrate exec version=20240101000000

Clear all migrations:

Terminal window
# Migrate to version 0
wheels dbmigrate exec version=0
# Verify empty state
wheels dbmigrate info

Executing migrations out of order can cause issues if migrations have dependencies. Always ensure that any required preceding migrations have been run.

The command updates the migration tracking table to reflect the execution status.

  1. Check Dependencies: Ensure required migrations are already applied
  2. Test First: Run in development/testing before production
  3. Use Sparingly: Prefer normal migration flow with up/latest
  4. Document Usage: Record when and why specific executions were done
  5. Verify State: Check migration status before and after execution

Migration versions are typically timestamps in the format:

  • YYYYMMDDHHmmss (e.g., 20240115123456)
  • Year: 2024
  • Month: 01
  • Day: 15
  • Hour: 12
  • Minute: 34
  • Second: 56
  • The command will migrate UP or DOWN to reach the specified version
  • Version must be a valid migration version or 0 to reset all
  • The migration file must exist in the migrations directory
  • The command displays the migration progress message
  • Both up() and down() methods should be defined in the migration