承接 rhubarbphp/module-migrations 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

rhubarbphp/module-migrations

Composer 安装命令:

composer require rhubarbphp/module-migrations

包简介

Provides scripted updates for managed transitions in application versions

README 文档

README

Commonly, when applications are upgraded there are breaking changes that require a scripted solution. This module provides a framework to: quickly generate migration scripts; manage the local version of an instance of your application, and; run migration scripts in order to bring your local version up-to-date with the current project version.

Setting the application version

The current application version needs to be defined when your project is initialized. The version must be an integer.

class MyApplication extends Application
{
    public function initialise()
    {
        // ...
        $this->version = 12; 
        // ...
    }
}

Creating a migration script

A migration script must implement the MigrationScriptInterface.

execute() is the logic of the migration.

version() must return an integer and defines on which application version this script should be executed. Migrations are executed in an order of version. Migrations on the same version are executed in the order they are registered.

class ImageDeletionScript extends MigrationScript
{
        public function execute()
        {
            foreach (Image::all(new Equals('active', false)) as $image) {
                unlink($image->filePath);
                $image->delete();
            }
        }
    
        public function version(): int
        {
            return 17;
        }
}

Registering your script

Scripts will not be ran unless they are registered. Scripts are registered by calling registerMigrationScripts($scriptsArray) on MigrationsModule.

   MigrationsManager::getMigrationsManager()->registerMigrationScripts([
       SplitNameColumnScript::class,
       DeleteAllImagesScript::class,
       UpdatedGdprInfoScript::class
   ]);

Custard Commands

migrations:migrate

The primary migrate command. All registered migration scripts with a version of or between the current locally stored version and the application version defined in code will be loaded and executed.

Options
Option shortcut Description
Skip Scripts -s It is possible to skip certain scripts, for example if you are re-running a failed migration and do not want to include the failing script. To do so include the option -s followed by the full path of the script to skip. You can include multiple scripts with -s.
Example

custard migrations:migrate -s My\Project\Scripts\NewMigrationScript.php -s My\Project\Scripts\DestroyOldDataScript.php

migrations:run-script

Takes the full path of a script and immediately executes it.

Example

custard migrations:run-script My\Project\Scripts\NewMigrationScript.php

MigrationsManager

The MigrationsManager is used to register and retrieve Migration Scripts. It's core function is to provide a set of active, valid and ordered migration scripts within a range via the getMigrationScripts() function.

The MigrationsManager implemented the Singleton trait and can be accessed via MigrationsManager::getMigrationsManager()

MigrationsStateProvider

The MigrationsStateProvider handles the current local version of the application and which migration scripts have been run. It must implement the following methods:

getLocalVersion() retrieves the local version. Must return an integer.

setLocalVersion(int $newLocalVersion) updates the local version.

markScriptCompleted(MigrationScriptInterface $migrationScript) locally stores a script as having been successfully executed.

isScriptComplete(string $className) checks if a script has already been successfully executed.

getCompletedScripts()

rhubarbphp/module-migrations 适用场景与选型建议

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

它主要适用于以下技术方向: 「framework」 「php」 「version」 「migration」 「script」 「rhubarb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2018-10-10