Overview
WPZylos Migrations provides database migration runner using WordPress dbDelta.
Key Features
- dbDelta Based - Uses WordPress's table creation function
- Migration Tracking - Stored in wp_options/wp_sitemeta
- Rollback Support -
up()anddown()methods - Multisite Aware - Site or network scoped migrations
Quick Start
use WPZylos\Framework\Migrations\Migrator;
$migrator = $app->make(Migrator::class);
$ran = $migrator->run();
$migrator->rollback(1);
$migrator->status();
Migration Class
class CreateProductsTable extends Migration
{
public function up(): void
{
$this->create('products', [
'id' => 'bigint(20) unsigned NOT NULL AUTO_INCREMENT',
'name' => 'varchar(255) NOT NULL',
'price' => 'decimal(10,2) NOT NULL',
'created_at' => 'datetime NOT NULL',
], ['PRIMARY KEY (id)']);
}
public function down(): void
{
$this->drop('products');
}
}
API Reference
| Method | Parameters | Returns | Description |
|---|---|---|---|
run | — | array | Run pending migrations |
rollback | int $steps = 1 | array | Rollback migrations |
status | — | array | Get migration status |
reset | — | array | Rollback all |