foogile / wp-cli-mig
General migration command for WP-CLI
Installs: 12 146
Dependents: 0
Suggesters: 0
Security: 0
Stars: 23
Watchers: 4
Forks: 1
Open Issues: 1
Type:wp-cli-package
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-12-27 21:59:31 UTC
README
General migration command for WP-CLI
Example migration
-
Create migration script
// filename: migrations/1_FirstMigration.php namespace WpCliMigrate; use Foogile\WpCli\Migrate\MigrationInterface; class FirstMigration implements MigrationInterface { public function up() { // Do some work using WordPress API } public function down() { // Undo some work using WordPress API } }
-
Move into folder migrations and execute migrations using WP-CLI
# Migrate to version 1 wp --require=/path/to/command.php mig to 1 # Migrate to version 2 wp --require=/path/to/command.php mig to 2 # Revert all migrations wp --require=/path/to/command.php mig to 0 # Status wp --require=/path/to/command.php mig status
For migrations that should stop execution, throw exceptions from up/down-methods. I.e.
a non-reversable migration will typically refuse a down()
-operation: throw new \Exception("Cannot rollback migration")
.