Migrating multiple databases using doctrine2 with Symfony2

Viewed 8768

I have 2 databases db1 and db2 in symfony2 + doctrine2 and both databases are different from each other in terms of tables and their fields.

I need to work on migration. Things work fine as long as there is one database.

But it does not works when there are more than one databases.

Also, is there any way where I can provide entity manager specific migration settings.

Or is there any way through which I can provide connection or entity manager in the migration class.

4 Answers

I've been using @iisisrael's answer for years. But after upgrading to doctrine/migrations 3.x I had to change the format of the config files. This is what I have now:

# config/packages/migrations/base.yaml
em: default
transactional: false
migrations_paths:
    Hyra\Migrations\Base: src/Migrations/Base
table_storage:
    table_name: migration_versions
# config/packages/migrations/special.yaml
em: special
transactional: false
migrations_paths:
    App\Migrations\Special: src/Migrations/Special
table_storage:
    table_name: migration_versions

And then I have these in my Makefile so that I don't need to remember the magic incantations:

migrate: migrate-base migrate-special

migrate-base:
    php bin/console doctrine:migrations:migrate --configuration=config/packages/migrations/base.yaml --no-interaction --allow-no-migration

migrate-special:
    php bin/console doctrine:migrations:migrate --configuration=config/packages/migrations/special.yaml --no-interaction --allow-no-migration

diff-migrations-base: migrate
    php bin/console doctrine:migrations:diff --configuration=config/packages/migrations/base.yaml

diff-migrations-special: migrate
    php bin/console doctrine:migrations:diff --configuration=config/packages/migrations/special.yaml
Related