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.
Kindly help.
Thanks..
The similar problem and solution: Symfony2 - Change Migration Directory
You can create another migration folder for second DB and put migrations inside.
This question is a little old, but it came up first when I was asking the same thing. I found my answer in the Doctrine migrations configuration docs. Let's say you have connections for two databases, each with their own entity managers (mapped here with XML, not annotations, and not auto mapped so the schema configs can live in the same
config/doctrine
path):Then you do not include the
doctrine_migrations
configurations inconfig.yml
. Instead, create a configuration file for each one:Then, whenever you run any migration command, specify both the entity manager and configuration:
It's a bit to remember if running by hand, so you might want to wrap them up in your own command to make life easy (e.g. something like
bin/console my:migrations:status --env=dev --db=special
). It's also not an issue if you have a deploy bash script, like:You can provide an entityManager using --em=name option in the migration task. I also add this piece of code, to avoid executing of the migration on another db by mistake:
I haven't found any other way to check the EM, so I can't help you if your databases have same names.
Also note, that you should add the skipIf to all your migrations, so you can migrate without worry in both you databases.