enshtein/wp-migrations 问题修复 & 功能扩展

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

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

enshtein/wp-migrations

Composer 安装命令:

composer create-project enshtein/wp-migrations

包简介

A WordPress library for managing database table schema upgrades and data seeding.

README 文档

README

A WordPress library for managing database table schema upgrades and data seeding.

Installation

  • composer require enshtein/wp-migrations
  • bootstrap the package by adding \Enshtein\WpMigrations\Migrate::instance(); to an mu-plugin.

Migrations

By default, the command will look for migration files in migrations directory alongside the vendor folder.

Use

Simply run wp migrate on the command line using WP CLI and any migrations not already run will be executed.

Create a migration file

wp migrate create add_price_table

<?php

use Enshtein\WpMigrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        global $wpdb;

        // up migration code
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        global $wpdb;

        // down migration code
    }
};

wp migrate create add_price_table --table=price

<?php

use Enshtein\WpMigrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        global $wpdb;

        $_sql = "CREATE TABLE `{$wpdb->prefix}price` (
           `id` int(10) NOT NULL auto_increment,
           PRIMARY KEY (id)
        ) {$this->collation()}";
				
        dbDelta($_sql);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        global $wpdb;

        $wpdb->query("DROP TABLE IF EXISTS `{$wpdb->prefix}price`");
    }
};

Other migration commands

  • wp migrate reset - command will roll back all of your application's migrations

  • wp migrate refresh - command will roll back all of your migrations and then execute the migrate command

  • wp migrate rollback - command rolls back the last "batch" of migrations, which may include multiple migration files

  • wp migrate rollback --step=3 - you may roll back a limited number of migrations by providing the step option to the rollback command

  • wp mimgrate status - if you would like to see which migrations have run thus far

Configuration

\Enshtein\WpMigrations\Migrate::instance([
    'command' => 'migrate',
    'table_name' => 'migrations',
    'folder' => 'migrations',
    'path' => '',
    'filename' => 'Y_m_d_His_',
]);
  • command - database table name to store migrations
  • table_name - the main command used to run through WP-CLI
  • folder - folder name with migration files
  • path - absolute path to the directory with migration files
  • filename - migration file name template

enshtein/wp-migrations 适用场景与选型建议

enshtein/wp-migrations 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 enshtein/wp-migrations 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 enshtein/wp-migrations 我们能提供哪些服务?
定制开发 / 二次开发

基于 enshtein/wp-migrations 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-11