问题描述
如何更改 config.yml 中的默认迁移目录?现在我正在使用 2 个具有不同 db-connections 的捆绑包,我想创建迁移文件并将它们存储在不同的目录中,以便在捆绑包的依赖中使用教义:迁移:迁移 --em=whatever 函数.
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: 'AcmeCommonBundleDoctrineMigrations'
如果您想要一些更复杂的事情,例如将 em1 到 dir1 的迁移放在 bundle1 中,并将从 em2 到 dir2 的迁移放在 bundle2 中,您将需要另外两个配置文件,您将在其中指定特定捆绑包的 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:
然后你像这样运行你的迁移:
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
migrations.yml 文件应如下所示:
By https://github.com/doctrine/DoctrineMigrationsBundle/pull/46
the migrations.yml file should look like:
name: Doctrine Postgres Migrations
migrations_namespace: ApplicationMigrations
table_name: migration_versions
migrations_directory: PostgreSqlMigrations
这篇关于Symfony2 - 更改迁移目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!