zenstruck / migrations-bundle
v2.1.1
2013-01-11 13:21 UTC
Requires
This package is not auto-updated.
Last update: 2022-02-01 12:20:27 UTC
README
注意: DoctrineMigrationsBundle 现在支持容器感知迁移
DoctrineMigrationsBundle的包装器,允许容器感知迁移。
注意: 要与Symfony 2.0
一起使用,请使用1.x
分支
安装
-
添加到
composer.json
(参见https://getcomposer.org.cn/)"require" : { "zenstruck/migrations-bundle": "*", }
-
注册包
<?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(); } }