kynetcode/wpzylos-migrations
Composer 安装命令:
composer require kynetcode/wpzylos-migrations
包简介
dbDelta-based migration runner for WPZylos framework
README 文档
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
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-06-16