foogile / wp-cli-mig
WP-CLI 通用迁移命令
v0.0.2
2014-03-31 12:10 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-20 20:51:50 UTC
README
WP-CLI 通用迁移命令
示例迁移
-
创建迁移脚本
// 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 } }
-
将脚本移动到 migrations 文件夹并使用 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
对于应该停止执行的迁移,从 up/down 方法中抛出异常。例如,不可逆的迁移通常拒绝 down() 操作:throw new \Exception("Cannot rollback migration")
。