kynetcode / wpzylos-migrations
dbDelta-based migration runner for WPZylos framework
Fund package maintenance!
v1.0.0
2026-06-16 18:53 UTC
Requires
- php: ^8.0
- kynetcode/wpzylos-core: ^1.0
- kynetcode/wpzylos-database: ^1.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.6 || ^10.0
- squizlabs/php_codesniffer: ^3.7
- szepeviktor/phpstan-wordpress: ^1.3
README
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 Methods —
create(),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