Skip to main content
How to apply generated Migration files to the database.

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

Execution Result:
migrate run executes all pending migrations in order.

Check Execution Status

Example Output:

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.
A target selection prompt appears.
When NODE_ENV is not local, only the connection whose name matches the environment is allowed. Choosing any other target fails with Migration targets are not allowed in NODE_ENV=....
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 run once puts them in the same batch

Environment-specific Execution

Development Environment

Staging Environment

Production Environment

Before running in production: 1. Test in staging first 2. Confirm backup is complete 3. Plan for downtime 4. Prepare rollback plan

Transactions

Automatic Transactions

Each migration runs in a separate transaction:

Disabling Transactions

Some DDL operations may not support transactions.

Error Handling

Error During Execution

Error Occurred:
Handling:
  1. Fix the migration file
  2. Retry execution

Partial Failure

When a migration fails: - Only that migration is rolled back - Previous migrations are retained - Not recorded in knex_migrations table

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