Command Line Tools
wheels dbmigrate latest
wheels dbmigrate latest
Section titled βwheels dbmigrate latestβRun all pending database migrations to bring database to latest version.
Synopsis
Section titled βSynopsisβwheels dbmigrate latestAlias: wheels db latest
Description
Section titled β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.
Parameters
Section titled βParametersβNone.
How It Works
Section titled βHow It Worksβ- Retrieves current database version and latest version
- Executes
dbmigrate execwith the latest version - Automatically runs
dbmigrate infoafter completion - Updates version tracking after successful migration
Example Output
Section titled βExample Outputβ================================================== Updating Database Schema to Latest Version==================================================
Latest Version: 20260123185445================================================== Migration Execution==================================================
Target Version: 20260123185445--------------------------------------------------Sending: http://0.0.0.0:8080/?controller=wheels&action=wheels&view=cli&command=migrateTo&version=20260123185445[SUCCESS]: Call to bridge was successful.[SUCCESS]: Migration completed successfully!
Sending: http://0.0.0.0:8080/?controller=wheels&action=wheels&view=cli&command=info[SUCCESS]: Call to bridge was successful.================================================== Database Migration Status==================================================
Database Information--------------------------------------------------Datasource: dbapp_testDatabase Type: MySQL
Migration Status--------------------------------------------------Total Migrations: 17Available Migrations: 14Current Version: 20260116163515Latest Version: 20260123185445--------------------------------------------------
Migration Files--------------------------------------------------ββββββββββββ€ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ STATUS β FILE ββ βββββββββββͺβββββββββββββββββββββββββββββββββββββββββββββββββββββββ£β β 20260123185445_cli_create_table_user βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260123183026_cli_remove_table_blog_posts βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260123182948_create_blog_posts_table βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260122173254_cli_create_table_user_roles βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260119145114_cli_create_column_parts_feature βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260119144642_cli_blank_students βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260119112924_cli_create_table_students βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260119111943_cli_create_table_books βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260116170453_cli_create_table_users βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260116170311_cli_create_table_users βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260116165727_cli_create_column_user_required_field βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260116164432_cli_create_column_product_price βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260116164211_cli_create_column_user_bio βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β β 20260116163907_cli_create_column_user_email βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β migrated β 20260116163515_cli_blank_create_reporting_procedures βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β migrated β 20260116160315_cli_remove_table_resources βββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ’β migrated β 20260116155320_cli_remove_table_users βββββββββββββ§βββββββββββββββββββββββββββββββββββββββββββββββββββββββMigration Execution
Section titled βMigration ExecutionβEach migration file must contain:
component extends="wheels.migrator.Migration" {
function up() { // Database changes go here transaction { // Use transaction for safety } }
function down() { // Rollback logic (optional) transaction { // Reverse the up() changes } }
}Transaction Safety
Section titled βTransaction SafetyβMigrations run within transactions:
- All changes in a migration succeed or fail together
- Database remains consistent
- Failed migrations can be retried
Common Migration Operations
Section titled βCommon Migration OperationsβCreate Table
Section titled βCreate Tableβfunction up() { transaction { t = createTable("products"); t.string("name"); t.decimal("price"); t.timestamps(); t.create(); }}Add Column
Section titled βAdd Columnβfunction up() { transaction { addColumn(table="users", columnNames="email", type="string"); }}Add Index
Section titled βAdd Indexβfunction up() { transaction { addIndex(table="users", columnNames="email", unique=true); }}Modify Column
Section titled βModify Columnβfunction up() { transaction { changeColumn(table="products", columnNames="price", type="decimal", precision=10, scale=2); }}Best Practices
Section titled βBest Practicesβ-
Test migrations locally first
Terminal window # Test on development databasewheels dbmigrate latest# Verifywheels dbmigrate info -
Backup before production migrations
Terminal window # Backup databasemysqldump myapp_production > backup.sql# Run migrationswheels dbmigrate latest -
Use transactions
function up() {transaction {// All changes here}} -
Make migrations reversible
function down() {transaction {dropTable("products");}}
Environment-Specific Migrations
Section titled β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')"); } }}Checking Migrations
Section titled βChecking MigrationsβPreview migrations before running:
# Check what would runwheels dbmigrate info
# Review migration filesls app/migrator/migrations/Performance Considerations
Section titled β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
Section titled βContinuous IntegrationβAdd to CI/CD pipeline:
- name: Run migrations run: | wheels dbmigrate latest wheels test appRollback Strategy
Section titled βRollback StrategyβIf issues occur after migration:
-
Use down migrations
Terminal window wheels dbmigrate downwheels dbmigrate down -
Restore from backup
Terminal window mysql myapp_production < backup.sql -
Fix and retry
- Fix migration file
- Run
wheels dbmigrate latest
Common Issues
Section titled βCommon IssuesβTimeout on Large Tables
Section titled βTimeout on Large Tablesβfunction up() { // Increase timeout for large operations setting requestTimeout="300";
transaction { // Long running operation }}Foreign Key Constraints
Section titled βForeign Key Constraintsβfunction up() { transaction { // Disable checks temporarily sql("SET FOREIGN_KEY_CHECKS=0");
// Make changes dropTable("orders");
// Re-enable sql("SET FOREIGN_KEY_CHECKS=1"); }}See Also
Section titled βSee Alsoβ- wheels dbmigrate info - Check migration status
- wheels dbmigrate up - Run single migration
- wheels dbmigrate down - Rollback migration
- wheels dbmigrate create blank - Create migration