5

如何更改 config.yml 中的默认迁移目录?现在我正在使用 2 个具有不同 db-connections 的捆绑包,我想创建迁移文件并将它们存储在不同的目录中,以便在捆绑包的依赖中使用教义:迁移:迁移 --em=whatever 函数。

例如:

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
4

3 回答 3

13

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

app/
    DoctrineMigrations/
        entityManager1/
        entityManager2/

如果你想把所有迁移到另一个目录,你可以在你的 config.yml 中设置它:

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

如果您想要一些更复杂的事情,例如将迁移从 em1 到 dir1 放在 bundle1 中,并将从 em2 迁移到 dir2 放在 bundle2 中,您将需要另外两个配置文件,您将在其中指定特定捆绑包的目录:

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

然后你像这样运行你的迁移:

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
文件应如下所示:

name: Doctrine Postgres Migrations  
migrations_namespace: Application\Migrations  
table_name: migration_versions  
migrations_directory: PostgreSqlMigrations  
于 2013-06-12T13:34:14.620 回答
5

对于发现此页面并花费数小时尝试实施 Cyprian 解决方案的其他人来说,它不起作用。

首先,--configuration被破坏,其次,学说迁移包不支持多个实体管理器。

请参阅https://github.com/doctrine/DoctrineMigrationsBundle/issues/18了解有关信息,--configuration并参阅https://github.com/doctrine/DoctrineMigrationsBundle/pull/46了解支持多个实体管理器的开放拉取请求。

如果 PR #46 通过,这将是一个简单的配置:

学说迁移:
  默认:
    目录名:...
    命名空间:...
  em2:
    目录名:...
    命名空间:...

目前唯一可用的调整是:

学说迁移:
    dir_name: '%kernel.root_dir%/../Acme/CommonBundle/DoctrineMigrations'
    命名空间:'Acme\CommonBundle\DoctrineMigrations'

但这将更新所有实体管理器中所有迁移的配置。

于 2013-10-25T17:51:45.527 回答
1

对于 Symfony 4,推荐的方法是使用%kernel.project_dir%,并将其放在src/命名空间为 的文件夹中App\

doctrine_migrations:
    dir_name: '%kernel.project_dir%/src/DoctrineMigrations'
    namespace: 'App\DoctrineMigrations'
于 2019-05-30T18:32:15.280 回答