kynetcode/wpzylos-migrations

dbDelta-based migration runner for WPZylos framework

Maintainers

Package info

github.com/KYNetCode/wpzylos-migrations

Documentation

pkg:composer/kynetcode/wpzylos-migrations

Fund package maintenance!

Paypal

Statistics

Installs: 15

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-16 18:53 UTC

This package is auto-updated.

Last update: 2026-06-16 20:01:24 UTC


README

PHP Version License GitHub

dbDelta-based migration runner for WPZylos framework.

📖 Full Documentation | 🐛 Report Issues

✨ Features

  • dbDelta Integration — Uses WordPress dbDelta for safe schema changes
  • Batch Tracking — Tracks migration history with batch numbers
  • Up/Down Methods — Reversible migrations
  • CLI Support — Run migrations via WP-CLI
  • Helper Methodscreate(), drop(), charsetCollate(), runDbDelta()

📋 Requirements

Requirement Version
PHP ^8.0
WordPress 6.0+

🚀 Installation

composer require KYNetCode/wpzylos-migrations

📖 Quick Start

Register ServiceProvider

$app->register(new \WPZylos\Framework\Migrations\MigrationsServiceProvider());

Write a Migration

<?php

namespace MyPlugin\Database\Migrations;

use WPZylos\Framework\Migrations\Migration;

class CreateProductsTable extends Migration
{
    public function up(): void
    {
        $this->create('myplugin_products', [
            'id'         => 'bigint(20) unsigned NOT NULL AUTO_INCREMENT',
            'name'       => 'varchar(255) NOT NULL',
            'price'      => 'decimal(10,2) NOT NULL DEFAULT 0.00',
            'created_at' => 'datetime DEFAULT CURRENT_TIMESTAMP',
        ], [
            'PRIMARY KEY (id)',
        ]);
    }

    public function down(): void
    {
        $this->drop('myplugin_products');
    }
}

🏗️ Core Features

Migration Helpers

// Create table (auto-prefixed, uses dbDelta)
$this->create('table_name', $columns, $keys);

// Drop table
$this->drop('table_name');

// Raw SQL via dbDelta
$this->runDbDelta($sql);

// Charset collation
$charset = $this->charsetCollate();

// Access database connection
$this->db->query('ALTER TABLE ...');

Running Migrations

$migrator = $app->make(Migrator::class);
$migrator->run();           // Run pending migrations
$migrator->rollback();      // Rollback last batch
$migrator->rollback(2);     // Rollback last 2 migrations
$status = $migrator->status(); // Get migration status

MigrationRepository

The MigrationRepository class tracks migration history in the database — which migrations have been run, their batch numbers, and ordering. It is used internally by the Migrator.

$repository = $app->make(MigrationRepository::class);
$repository->getRan();        // Get all ran migration names
$repository->getLastBatch();  // Get migrations from last batch
$repository->log($file, $batch); // Record a migration as run
$repository->delete($migration); // Remove a migration record

📦 Related Packages

Package Description
wpzylos-core Application foundation
wpzylos-database Query builder
wpzylos-scaffold Plugin template

📖 Documentation

For comprehensive documentation, tutorials, and API reference, visit wpzylos.com.

Support the Project

📄 License

MIT License. See LICENSE for details.

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Made with ❤️ by KYNetCode