mpoiriert/nucleus-migration-bundle

基于命令执行迁移脚本的Bundle

dev-master 2014-03-26 17:37 UTC

This package is auto-updated.

Last update: 2024-09-09 13:44:49 UTC


README

构建状态由于Travis命令行测试的问题,它们可能现在正在出错。

使用此Bundle,您将能够管理迁移脚本。通过配置,您将能够调用多个命令,就像您使用CLI一样。

要在您的应用程序中使用它,您必须注册3个Bundle,因为依赖于nucleus-bundlenucleus-console-bundle

<?php

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Nucleus\Bundle\CoreBundle\NucleusCoreBundle(),
    new Nucleus\Bundle\BinderBundle\NucleusConsoleBundle(),
    new Nucleus\Bundle\BinderBundle\NucleusMigrationBundle(),
    // ...
);

从那里,您必须进行配置

nucleus_migration:
    versions: [v1,v2]
    tasks:
        v1:
            - {command: "command:name1", parameters: {} }
            - {command: "command:name2", parameters: {param1: value1}, salt: first}
            - {command: "command:name3", parameters: {param1: value1}, salt: second}
        v2:
            ...
        v3:
            ...

此配置文件告诉系统您要执行迁移版本v1和v2。v3版本的任务将不会执行,因为v3没有在versions配置中提及。

任务本身在tasks下相应版本的相应部分中进行配置。

迁移系统提供了5种不同的命令

nucleus_migration:report
    Will output a report of all the task with a unique id and if they have been run or not

nucleus_migration:runAll
    Will run all the migration script (once) configure in the specific order.

nucleus_migration:markAllAsRun
    Will mark all the task like they have been run

nucleus_migration:runById
    Will run a task by it's id. The task will be run event if it already have been run. You can fin the id of the
    task in the report

nucleus_migration:manual
    Allow to run the execution flow manually. You will be prompt on each task if you want to run them or not

任务的ID基于命令名称、参数以及在需要两次使用相同参数运行任务时使用的盐。ID不使用版本名称,如果您将任务从一个版本移动到另一个版本,它将具有相同的ID。

请确保覆盖%nucleus.variable_registry.class%参数,以便nucleus.variable_registry服务持久化。默认提供的只保留信息在内存中。

请注意,迁移系统仅支持向前移动版本,如果您想向后移动,您需要自行进行备份并制定恢复计划。根据我的经验,您应该构建一个始终向后兼容的系统,有时通过脚本恢复数据几乎是不可能的,因此请确保您所做的是正确的。

要轻松创建新命令,请参阅nucleus-console-bundle