使用doctrine2和Symfony2迁移多个数据库 [英] Migrating multiple databases using doctrine2 with Symfony2

查看:70
本文介绍了使用doctrine2和Symfony2迁移多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在symfony2 + doctrine2中有2个数据库db1和db2,这两个数据库在表及其字段方面都互不相同.

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.

推荐答案

您可以在迁移任务中使用--em = name选项提供一个entityManager.我还添加了这段代码,以避免错误地在另一个数据库上执行迁移:

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'
    );

我没有找到其他方法来检查EM,因此如果您的数据库名称相同,我将无济于事.

I haven't found any other way to check the EM, so I can't help you if your databases have same names.

还请注意,您应该将skipIf添加到所有迁移中,这样您就可以在两个数据库中进行迁移而不必担心.

Also note, that you should add the skipIf to all your migrations, so you can migrate without worry in both you databases.

这篇关于使用doctrine2和Symfony2迁移多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆