smartteam/migrations-bundle

旧 ZenstruckMigrationsBundle 的维护项目

安装: 614

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 4

类型:symfony-bundle

v2.2.0 2018-01-18 05:38 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:01:44 UTC


README

旧 ZenstruckMigrationsBundle 的维护项目,该 Bundle 允许容器感知迁移。

注意:要用于 Symfony 2.0,请使用 1.x 分支

安装

  1. 将以下内容添加到 composer.json 文件中(见 http://getcomposer.org/

    "require" :  {
        "smartteam/migrations-bundle": "*",
    }
  2. 注册该 Bundle

    <?php
    // app/AppKernel.php
    
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new SmartTeam\Bundle\MigrationsBundle\SmartTeamMigrationsBundle(),
        );
        // ...
    )

用法

  • 要使用容器感知数据迁移,您的迁移必须扩展 SmartTeam\Bundle\MigrationsBundle\Migrations\AbstractMigration。(注意:扩展 Doctrine\DBAL\Migrations\AbstractMigration 的迁移仍将正常运行)
  • 实现 dataUp() 方法并添加您的自定义迁移逻辑。(注意:将先运行 up() 方法,然后运行 dataUp)
  • 实现 dataDown() 方法并添加您的自定义迁移逻辑。(注意:将先运行 down() 方法,然后运行 dataDown)
  • 可选 实现 getDataDescription 方法并返回迁移的描述。
  • 使用 smartteam:migrations:migrate 命令进行迁移。(注意:请确保使用此命令运行迁移,而不是使用 doctrine:migrations:migrate 命令)

迁移模板

<?php

namespace Application\Migrations;

use SmartTeam\Bundle\MigrationsBundle\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Auto-generated Migration: Please modify to your need!
 */
class Version20120419113825 extends AbstractMigration
{
    public function up(Schema $schema)
    {
        // this up() migration is autogenerated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");

    }

    public function down(Schema $schema)
    {
        // this down() migration is autogenerated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");

    }
    
    public function dataUp(ContainerInterface $container)
    {
        // container aware logic
    }
    
    public function dataDown(ContainerInterface $container)
    {
        // container aware logic
    }

    /**
     * OPTIONAL
     */
    public function getDataDescription()
    {
        return parent::getDataDescription();
    }
}