Run all pending database migrations to bring database to latest version.
Synopsis
wheels dbmigrate latest
Description
The wheels dbmigrate latest command runs all pending migrations in chronological order, updating your database schema to the latest version. This is the most commonly used migration command.
→ Running 20240120140000_add_status_to_orders.cfc
Adding column: status to orders
✗ ERROR: Column 'status' already exists
Migration failed at version 20240115120000
Error: Column 'status' already exists in table 'orders'
To retry: Fix the migration file and run 'wheels dbmigrate latest' again
To skip: Run 'wheels dbmigrate up' to run one at a time
Best Practices
Test migrations locally first
# Test on development database
wheels dbmigrate latest
# Verify
wheels dbmigrate info
function up() {
transaction {
// All changes here
}
}
Make migrations reversible
function down() {
transaction {
dropTable("products");
}
}
Environment-Specific Migrations
Migrations can check environment:
function up() {
transaction {
// Always run
addColumn(table="users", column="lastLogin", type="datetime");
// Development only
if (get("environment") == "development") {
// Add test data
sql("INSERT INTO users (email) VALUES ('test@example.com')");
}
}
}
Dry Run
Preview migrations without running:
# Check what would run
wheels dbmigrate info
# Review migration files
ls db/migrate/
Performance Considerations
For large tables:
function up() {
transaction {
// Add index concurrently (if supported)
if (get("databaseType") == "postgresql") {
sql("CREATE INDEX CONCURRENTLY idx_users_email ON users(email)");
} else {
addIndex(table="users", columns="email");
}
}
}
Continuous Integration
Add to CI/CD pipeline:
# .github/workflows/deploy.yml
- name: Run migrations
run: |
wheels dbmigrate latest
wheels test app
Rollback Strategy
If issues occur after migration:
Use down migrations
wheels dbmigrate down
wheels dbmigrate down
Restore from backup
mysql myapp_production < backup.sql
Fix and retry
Fix migration file
Run wheels dbmigrate latest
Common Issues
Timeout on Large Tables
function up() {
// Increase timeout for large operations
setting requestTimeout="300";
transaction {
// Long running operation
}
}