The Migrations library provides WP-CLI commands for managing and monitoring migrations from the command line. This is useful for running migrations in controlled environments, debugging issues, and monitoring execution status.
All commands are registered under the {prefix} migrations namespace, where {prefix} is determined by your configured hook prefix (converted to lowercase with underscores/spaces replaced by hyphens).
For example, if you configured:
Config::set_hook_prefix( 'my_plugin' );The commands will be available as:
wp my-plugin migrations <command>Lists all registered migrations.
wp {prefix} migrations list [--tags=<tags>] [--format=<format>]Options:
| Option | Description | Default |
|---|---|---|
--tags=<tags> |
Comma-separated list of tags to filter by | (all migrations) |
--format=<format> |
Output format: table, json, csv, yaml |
table |
Output Columns:
id- The migration's unique identifierlabel- Human-readable labeldescription- Description of what the migration doestags- Assigned tagstotal_batches- Total number of batches to processcan_run- Whether the migration can currently runis_applicable- Whether the migration applies to this sitestatus- Current status
Examples:
# List all registered migrations
wp my-plugin migrations list
# List migrations with specific tags
wp my-plugin migrations list --tags=database,cleanup
# Output as JSON
wp my-plugin migrations list --format=jsonRuns a specific migration.
wp {prefix} migrations run <migration_id> [--from-batch=<batch>] [--to-batch=<batch>] [--batch-size=<size>] [--dry-run]Arguments:
| Argument | Description | Required |
|---|---|---|
<migration_id> |
The unique ID of the migration to run | Yes |
Options:
| Option | Description | Default |
|---|---|---|
--from-batch=<batch> |
Batch number to start from | 1 |
--to-batch=<batch> |
Batch number to end at | (last batch) |
--batch-size=<size> |
Number of items per batch (must be at least 1) | (migration default) |
--dry-run |
Preview what would be run without executing | (disabled) |
Examples:
# Run a migration
wp my-plugin migrations run rename_meta_key
# Run specific batches
wp my-plugin migrations run rename_meta_key --from-batch=5 --to-batch=10
# Run with custom batch size
wp my-plugin migrations run rename_meta_key --batch-size=50
# Preview what would be run (dry run)
wp my-plugin migrations run rename_meta_key --dry-runBehavior:
- Creates a new execution record with status
SCHEDULED - Processes each batch sequentially, displaying a progress bar
- Logs are written to the migration_logs table for each batch
Rolls back a specific migration.
wp {prefix} migrations rollback <migration_id> [--from-batch=<batch>] [--to-batch=<batch>] [--batch-size=<size>] [--dry-run]Arguments:
| Argument | Description | Required |
|---|---|---|
<migration_id> |
The unique ID of the migration to rollback | Yes |
Options:
| Option | Description | Default |
|---|---|---|
--from-batch=<batch> |
Batch number to start from | 1 |
--to-batch=<batch> |
Batch number to end at | (last batch) |
--batch-size=<size> |
Number of items per batch (must be at least 1) | (migration default) |
--dry-run |
Preview what would be rolled back without executing | (disabled) |
Examples:
# Rollback a migration
wp my-plugin migrations rollback rename_meta_key
# Rollback specific batches
wp my-plugin migrations rollback rename_meta_key --from-batch=1 --to-batch=5
# Preview what would be rolled back (dry run)
wp my-plugin migrations rollback rename_meta_key --dry-runLists execution records for a specific migration.
wp {prefix} migrations executions <migration_id> [--format=<format>]Arguments:
| Argument | Description | Required |
|---|---|---|
<migration_id> |
The unique ID of the migration | Yes |
Options:
| Option | Description | Default |
|---|---|---|
--format=<format> |
Output format: table, json, csv, yaml |
table |
Output Columns:
id- Execution ID (use this with thelogscommand)migration_id- The migration identifierstart_date_gmt- When the execution startedend_date_gmt- When the execution completedstatus- Execution status (SCHEDULED, RUNNING, COMPLETED, FAILED, REVERTED, CANCELED, PAUSED, PENDING, NOT_APPLICABLE)items_total- Total items to processitems_processed- Items processed so farcreated_at- When the execution was created
Status Values:
- COMPLETED - Migration finished successfully
- FAILED - Migration failed and was automatically rolled back
- REVERTED - Migration was manually rolled back successfully
- RUNNING - Migration is currently executing
- SCHEDULED/PENDING - Migration is queued to run
- CANCELED - Migration was canceled before completion
- PAUSED - Migration execution is paused
- NOT_APPLICABLE - Migration doesn't apply to this site
Examples:
# List executions for a migration
wp my-plugin migrations executions rename_meta_key
# Output as JSON for scripting
wp my-plugin migrations executions rename_meta_key --format=jsonLists log entries for a specific execution.
wp {prefix} migrations logs <execution_id> [--type=<type>] [--not-type=<types>] [--search=<term>] [--limit=<limit>] [--offset=<offset>] [--order=<order>] [--order-by=<column>] [--format=<format>]Arguments:
| Argument | Description | Required |
|---|---|---|
<execution_id> |
The execution ID (from executions command) |
Yes |
Options:
| Option | Description | Default |
|---|---|---|
--type=<types> |
Filter by log type(s): info, warning, error, debug. Comma-separated for multiple. |
(all types) |
--not-type=<types> |
Exclude log type(s). Comma-separated for multiple. | (none) |
--search=<term> |
Filter logs by search term in message | (no filter) |
--limit=<limit> |
Maximum number of results | 100 |
--offset=<offset> |
Skip first N results | 0 |
--order=<order> |
Sort order: ASC or DESC |
DESC |
--order-by=<column> |
Column to sort by | created_at |
--format=<format> |
Output format: table, json, csv, yaml |
table |
Output Columns:
id- Log entry IDtype- Log type (info, warning, error, debug)message- Log messagedata- Additional context data (JSON)created_at- When the log was created
Examples:
# View logs for an execution
wp my-plugin migrations logs 123
# View only errors
wp my-plugin migrations logs 123 --type=error
# View warnings and errors
wp my-plugin migrations logs 123 --type=warning,error
# Exclude debug messages
wp my-plugin migrations logs 123 --not-type=debug
# Search for specific text
wp my-plugin migrations logs 123 --search="failed to update"
# Paginate results
wp my-plugin migrations logs 123 --limit=50 --offset=100
# Sort oldest first
wp my-plugin migrations logs 123 --order=ASCNote: You cannot use --type and --not-type together.
wp my-plugin migrations listwp my-plugin migrations run my_migration_id# Check executions
wp my-plugin migrations executions my_migration_id
# View logs for the execution
wp my-plugin migrations logs 123# View only error logs
wp my-plugin migrations logs 123 --type=error
# Search for specific issues
wp my-plugin migrations logs 123 --search="failed" --type=error,warningwp my-plugin migrations rollback my_migration_idTo run migrations only via CLI (preventing automatic scheduling on page loads), use the stellarwp_migrations_{prefix}_automatic_schedule filter:
add_filter( 'stellarwp_migrations_my_plugin_automatic_schedule', '__return_false' );With this filter active, migrations will only run when explicitly triggered via WP-CLI.
| Code | Description |
|---|---|
0 |
Success |
1 |
Error (invalid arguments, migration not found, etc.) |
All CLI commands support multiple output formats via the --format option: table (default), json, csv, and yaml.
The CLI automatically normalizes data for display:
- Enum values (e.g.,
Status,Log_Type) are converted to their string values - DateTime objects are formatted as ISO 8601 (ATOM) strings
- Arrays are joined with commas for table display
This ensures consistent, readable output across all formats.
Example:
# Table output (default) - human readable
wp my-plugin migrations list
# JSON output - for scripting and automation
wp my-plugin migrations list --format=json
# CSV output - for spreadsheet import
wp my-plugin migrations executions my_migration --format=csv- Getting Started - Basic usage guide
- Migration Contract - Full API reference
- Admin UI Reference - Admin interface for managing migrations
- REST API Reference - REST API endpoints for programmatic access
- Programmatic Scheduling - How to programmatically schedule migrations
- Hooks Reference - Available actions and filters