CLI Overview
Quick Start Guide
wheels info
wheels reload
wheels deps
wheels destroy
wheels watch
wheels generate app
wheels generate app-wizard
wheels generate controller
wheels generate model
wheels generate view
wheels generate property
wheels generate route
wheels generate resource
wheels generate api-resource
wheels generate frontend
wheels generate test
wheels generate snippets
wheels scaffold
wheels db create
wheels db drop
wheels db setup
wheels db reset
wheels db status
wheels db version
wheels db rollback
wheels db seed
wheels db dump
wheels db restore
wheels db shell
wheels db schema
wheels dbmigrate info
wheels dbmigrate latest
wheels dbmigrate up
wheels dbmigrate down
wheels dbmigrate reset
wheels dbmigrate exec
wheels dbmigrate create blank
wheels dbmigrate create table
wheels dbmigrate create column
wheels dbmigrate remove table
wheels test
wheels test run
wheels test coverage
wheels test debug
wheels config list
wheels config set
wheels config env
wheels env
wheels env setup
wheels env list
wheels env switch
wheels environment
wheels console
wheels runner
wheels server
wheels server start
wheels server stop
wheels server restart
wheels server status
wheels server log
wheels server open
wheels plugins
wheels plugins list
wheels plugins install
wheels plugins remove
wheels analyze
wheels analyze code
wheels analyze performance
wheels analyze security
wheels security
wheels security scan
wheels optimize
wheels optimize performance
wheels docs
wheels docs generate
wheels docs serve
wheels ci init
wheels docker init
wheels docker deploy
wheels deploy
wheels deploy audit
wheels deploy exec
wheels deploy hooks
wheels deploy init
wheels deploy lock
wheels deploy logs
wheels deploy proxy
wheels deploy push
wheels deploy rollback
wheels deploy secrets
wheels deploy setup
wheels deploy status
wheels deploy stop
Configuration Management
Creating Commands
Service Architecture
Migrations Guide
Testing Guide
Object Relational Mapping
Creating Records
Reading Records
Updating Records
Deleting Records
Column Statistics
Dynamic Finders
Getting Paginated Data
Associations
Nested Properties
Object Validation
Object Callbacks
Calculated Properties
Transactions
Dirty Records
Soft Delete
Automatic Time Stamps
Using Multiple Data Sources
wheels dbmigrate latest
Run all pending database migrations to bring database to latest version.
Synopsis
wheels dbmigrate latest
Alias: wheels db 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.
Parameters
None.
How It Works
- Retrieves current database version and latest version
- Executes
dbmigrate exec
with the latest version - Automatically runs
dbmigrate info
after completion - Updates version tracking after successful migration
Example Output
+-----------------------------------------+-----------------------------------------+
| Datasource: myApp | Total Migrations: 4 |
| Database Type: H2 | Available Migrations: 0 |
| | Current Version: 20250812161449 |
| | Latest Version: 20250812161449 |
+-----------------------------------------+-----------------------------------------+
+----------+------------------------------------------------------------------------+
| migrated | 20250812161449_cli__create_reporting_procedures |
| migrated | 20250812161302_cli__example_1 |
| migrated | 20250812161250_cli__example_2 |
| migrated | 20250812154338_cli__example_3 |
+----------+------------------------------------------------------------------------+
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
Migrations run within transactions:
- All changes in a migration succeed or fail together
- Database remains consistent
- Failed migrations can be retried
Common Migration Operations
Create Table
function up() {
transaction {
t = createTable("products");
t.string("name");
t.decimal("price");
t.timestamps();
t.create();
}
}
Add Column
function up() {
transaction {
addColumn(table="users", column="email", type="string");
}
}
Add Index
function up() {
transaction {
addIndex(table="users", columns="email", unique=true);
}
}
Modify Column
function up() {
transaction {
changeColumn(table="products", column="price", type="decimal", precision=10, scale=2);
}
}
Best Practices
-
Test migrations locally first
# Test on development database wheels dbmigrate latest # Verify wheels dbmigrate info
-
Backup before production migrations
# Backup database mysqldump myapp_production > backup.sql # Run migrations wheels dbmigrate latest
-
Use transactions
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')");
}
}
}
Checking Migrations
Preview migrations before running:
# Check what would run
wheels dbmigrate info
# Review migration files
ls app/migrator/migrations/
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
}
}
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
- wheels dbmigrate info - Check migration status
- wheels dbmigrate up - Run single migration
- wheels dbmigrate down - Rollback migration
- wheels dbmigrate create blank - Create migration
- Synopsis
- Parameters
- How It Works
- Example Output
- Migration Execution
- Transaction Safety
- Common Migration Operations
- Create Table
- Add Column
- Add Index
- Modify Column
- Best Practices
- Environment-Specific Migrations
- Checking Migrations
- Performance Considerations
- Continuous Integration
- Rollback Strategy
- Common Issues
- Timeout on Large Tables
- Foreign Key Constraints
- See Also