smartteam / migrations-bundle
旧 ZenstruckMigrationsBundle 的维护项目
v2.2.0
2018-01-18 05:38 UTC
Requires
README
旧 ZenstruckMigrationsBundle 的维护项目,该 Bundle 允许容器感知迁移。
注意:要用于 Symfony 2.0
,请使用 1.x
分支
安装
-
将以下内容添加到
composer.json
文件中(见 http://getcomposer.org/)"require" : { "smartteam/migrations-bundle": "*", }
-
注册该 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(); } }