定制 desaiuditd/enhanced-wp-migrations 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

desaiuditd/enhanced-wp-migrations

Composer 安装命令:

composer require desaiuditd/enhanced-wp-migrations

包简介

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.

Ever had to create a custom table for some plugin or custom code to use? To keep the site updated with the latest version of that table you need to keep track of what version the table is at. This can get overly complex for lots of tables.

This package is forked from deliciousbrains/wp-migrations with some improvements.

This package is inspired by Laravel's database migrations. You create a new migration PHP file, add your schema update code, and optionally include a rollback method to reverse the change.

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

The great thing about making database schema and data updates with migrations, is that the changes are file-based and therefore can be stored in version control, giving you better control when working across different branches.

Requirements

This package is designed to be used on a WordPress site project, not for a plugin or theme.

It needs to be running PHP 5.4 or higher.

You need to have access to run WP CLI on the server. Typically wp dbi migrate will be run as a last stage build step in your deployment process.

Key Differences from wp-migrations

  • Removed support for multiple migration directories. I've made assumption that all of your migration files should be located at one place only. So that the package can follow SemVer in the migration names and filenames (Similar to Flyway).
  • Individual migrations will be identified with their respective semver number. E.g., 1, 1.0.1, 1.1 etc.
  • wp edbm migrate command will use the version number of the migration instead of the class name. E.g., wp edbm migrate 2.0.1
  • Migration file name conventions is <version-number>.php. E.g., 1.php, 1.0.1.php, 2.1.php etc. Usually, you can start your migrations from 0.0.1.php.
  • Make sure you put only one class in one migration file.

Installation

  • composer require desaiuditd/enhanced-wp-migrations
  • Bootstrap the package by adding \EnhancedWPMigrations\Database\Migrator::instance(); to an mu-plugin.
  • Run wp edbm migrate --setup on the server.

Migrations

By default, the command will look for migration files in /app/migrations directory alongside the vendor folder. This can be altered with the filter edbm_wp_migrations_path.

An example migration to create a table would look like:

<!-- 0.0.1.php -->
<?php

use EnhancedWPMigrations\Database\AbstractMigration;

class AddCustomTable extends AbstractMigration {

    public function run() {
        global $wpdb;

        $sql = "
            CREATE TABLE " . $wpdb->prefix . "my_table (
            id bigint(20) NOT NULL auto_increment,
            some_column varchar(50) NOT NULL,
            PRIMARY KEY (id)
            ) {$this->get_collation()};
        ";

        dbDelta( $sql );
    }

    public function rollback() {
        global $wpdb;
        $wpdb->query( 'DROP TABLE ' . $wpdb->prefix . 'my_table');
    }
}

We are also using the migrations to deploy development data changes at deployment time. Instead of trying to merge the development database into the production one.

For example, to add a new page:

<!-- 0.0.1.php -->
<?php

use EnhancedWPMigrations\Database\AbstractMigration;

class AddPricingPage extends AbstractMigration {

    public function run() {
        $pricing_page_id = wp_insert_post( array(
            'post_title'  => 'Pricing',
            'post_status' => 'publish',
            'post_type'   => 'page',
        ) );
        update_post_meta( $pricing_page_id, '_wp_page_template', 'page-pricing.php' );
    }
}

Use

You can run specific migrations using the filename as an argument, eg. wp edbm migrate 2.1.1.

To rollback all migrations you can run wp edbm migrate --rollback, or just a specific migration wp edbm migrate 2.1.1 --rollback.

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2020-04-04