zenstruck/migrations-bundle

此包已被弃用且不再维护。作者建议使用doctrine/doctrine-migrations-bundle包。

DoctrineMigrationsBundle的包装器,允许容器感知迁移

资助包维护!
kbond

安装次数: 1,121

依赖者: 0

建议者: 0

安全: 0

星标: 3

关注者: 2

分支: 4

开放问题: 1

类型:symfony-bundle

v2.1.1 2013-01-11 13:21 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:20:27 UTC


README

注意: DoctrineMigrationsBundle 现在支持容器感知迁移

DoctrineMigrationsBundle的包装器,允许容器感知迁移。

注意: 要与Symfony 2.0一起使用,请使用1.x分支

安装

  1. 添加到composer.json(参见https://getcomposer.org.cn/

    "require" :  {
        "zenstruck/migrations-bundle": "*",
    }
  2. 注册包

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

用法

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

迁移模板

<?php

namespace Application\Migrations;

use Zenstruck\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();
    }
}