Symfony2 - 更改迁移目录 [英] Symfony2 - Change Migration Directory

查看:125
本文介绍了Symfony2 - 更改迁移目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改config.yml中的默认迁移dirctory?
现在我正在使用不同数据库连接的2个捆绑包,并且我想创建迁移文件并将它们存储在不同的目录中,以使用这个doctrine:migrations:migrate --em = bundle中的任何功能。

How can I change the default migration dirctory in the config.yml? Right now I am using 2 bundles with different db-connections and I would like to create migrations files and store them in different directories to use the doctrine:migrations:migrate --em=whatever function in depency of the bundle.

例如:

doctrine:migrate:diff --em=whatever #creating a version file in the DoctrineMigrationsWhatever directory

php app/console doctrine:migrations:status --em=whatever # shows only the version files, that belong to the bundle


推荐答案

如果您为此第二个连接/包创建单独的实体管理器,在您的DoctrineMigrations目录中获取另一个目录。例如:

If you'll create separate entity manager for this second connection/bundle you will get another directory in your DoctrineMigrations dir. For example:

app/
    DoctrineMigrations/
        entityManager1/
        entityManager2/

如果要将所有迁移放在另一个目录中,可以在config.yml中设置:

If you want put all migrations to another directory, you can set it inside your config.yml:

doctrine_migrations:
    dir_name: '%kernel.root_dir%/../Acme/CommonBundle/DoctrineMigrations'
    namespace: 'Acme\CommonBundle\DoctrineMigrations'

如果你想要一些更复杂的东西,如把em1的迁移到bundle1里面的dir1,并将bundle2中的em2迁移到dir2,你将需要一个额外的两个配置文件,你可以在这里指定特定bundle的dir:

If you want some more complex thing like put migrations from em1 to dir1 inside bundle1 and put migrations from em2 to dir2 inside bundle2 you will need an additional two configuration files where you'll specify dirs for particular bundles:

http://docs.doctrine-project.org/projects /doctrine-migrations/en/latest/reference/introduction.html#conf iguration

然后运行您的迁移,如下所示:

And then you run your migrations like this:

doctrine:migrations:status --em=em1 --configuration=./path/to/bundle1/Resources/config/migrations.yml
doctrine:migrations:status --em=em2 --configuration=./path/to/bundle2/Resources/config/migrations.yml

https://github.com/doctrine/DoctrineMigrationsBundle/pull/46

迁移.yml文件应如下所示:

By https://github.com/doctrine/DoctrineMigrationsBundle/pull/46
the migrations.yml file should look like:

name: Doctrine Postgres Migrations  
migrations_namespace: Application\Migrations  
table_name: migration_versions  
migrations_directory: PostgreSqlMigrations  

这篇关于Symfony2 - 更改迁移目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆