kynetcode/wpzylos-migrations 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kynetcode/wpzylos-migrations

Composer 安装命令:

composer require kynetcode/wpzylos-migrations

包简介

dbDelta-based migration runner for WPZylos framework

README 文档

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

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2026-06-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固