Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

migration - Migrating multiple databases using doctrine2 with Symfony2

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

    $parameters = $this->connection->getParams();
    $this->skipIf(
        $parameters['dbname'] != "my_db_name"
        'This is the other DB's migration, pass a correct --em parameter'
    );

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...