WPZylos Migrations

Database schema management with versioned migrations and dbDelta integration.

What You Get

  • Migrator — Run/rollback migrations
  • Version tracking — Stored in options table
  • dbDelta integration — Safe schema updates
  • CLI commandswp zylos migrate

Quick Start

use WPZylos\Framework\Migrations\Migrator;

$migrator = $app->make(Migrator::class);

// Run pending migrations
$ran = $migrator->run();

// Check status
$status = $migrator->status();

Migration Example

// database/migrations/2024_01_01_000001_create_orders_table.php
use WPZylos\Framework\Migrations\Migration;

return new class extends Migration
{
    public function up(): void
    {
        $table = $this->db->wpdb()->prefix . 'orders';

        $sql = "CREATE TABLE {$table} (
            id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
            user_id bigint(20) unsigned NOT NULL,
            total decimal(10,2) NOT NULL DEFAULT 0,
            status varchar(50) NOT NULL DEFAULT 'pending',
            created_at datetime DEFAULT CURRENT_TIMESTAMP,
            PRIMARY KEY  (id),
            KEY user_id (user_id)
        ) {$this->charsetCollate()};";

        $this->runDbDelta($sql);
    }

    public function down(): void
    {
        $this->dropTable('orders');
    }
};

Documentation