Execution Commands
migrate run
Run all migrations Update DB to latest
migrate status
Check execution status Pending list
migrate apply
Run against selected databases
migrate generate
Generate prepared migration files
sonamu migrate has exactly four subcommands: run, apply, generate, and status. Rollback
is not a CLI command — see Rolling Back.Basic Execution
Run All Migrations
migrate run executes all pending migrations in order.Check Execution Status
Execution Order
Migrations are executed in filename timestamp order:Targeting Specific Databases
migrate apply
migrate run applies migrations only to the database matching the current NODE_ENV (test and
fixture when NODE_ENV=test). To choose the targets yourself, use migrate apply.
There is no command to run a single migration at a time. The execution unit is always all pending migrations.
Batch System
What is a Batch?
A group of migrations executed together:Role of Batches
- Rollback unit: Migrations in the same batch are rolled back together
- Execution group: Running
migrate runonce puts them in the same batch
Environment-specific Execution
Development Environment
Staging Environment
Production Environment
Transactions
Automatic Transactions
Each migration runs in a separate transaction:Disabling Transactions
Some DDL operations may not support transactions.
Error Handling
Error During Execution
- Fix the migration file
- Retry execution
Partial Failure
Checking Execution Logs
Execution Result
migrate run prints the batch number and the list of applied files per target connection. There is
no option for SQL-level verbose logging, so use the knex_migrations queries below or your database
server logs to inspect the executed SQL.
Querying Execution History
CI/CD Integration
GitHub Actions
Docker
Minimizing Downtime
Blue-Green Deployment
Maintaining Compatibility
Practical Tips
1. Pre-execution Checks
2. Backup
3. Monitoring
Next Steps
Rolling Back
Undo from Sonamu UI
Strategies
Safe migration practices
Creating Migrations
Generate in Sonamu UI
How It Works
Understanding auto-generation