目录和子目录中的Symfony2 Doctrine Schema更新

时间:2015-02-27 11:28:21

标签: php entity-framework symfony doctrine-orm doctrine

我为许多客户提供了一种产品,但我希望拥有一个代码库。每个客户都需要在数据库(实体回购)和他自己的主题中进行一些特定的更改。每个客户都有自己的数据库。我需要找到一个解决方案,为每个客户定义配置,必须读取实体,以创建或更新自己的数据库模式。

在我的捆绑包中,我在实体中有这个结构

Acme\JobBundle\Entities\Customer.php
Acme\JobBundle\Entities\Customer1\Customer.php
Acme\JobBundle\Entities\Customer2\Customer.php
Acme\JobBundle\Entities\Customer3\Customer.php

Acme\JobBundle\Entities\Customer.php is an abstract class

Acme\JobBundle\Entities\Customer1\Customer.php extends Acme\JobBundle\Entities\Customer.php

感谢您的时间

1 个答案:

答案 0 :(得分:1)

相应于Symfony2 doc

您可以定义多个实体管理器和相关的映射:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
            customer:
                driver:   "%database_driver2%"
                host:     "%database_host2%"
                port:     "%database_port2%"
                dbname:   "%database_name2%"
                user:     "%database_user2%"
                password: "%database_password2%"
                charset:  UTF8

    orm:
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    AppBundle:  ~
                    AcmeStoreBundle: ~
            customer:
                connection: customer
                mappings:
                    AcmeCustomerBundle: ~

当然,您可以像这样创建架构:

# Play only with "default" mappings
$ php app/console doctrine:schema:update --force

# Play only with "customer" mappings
$ php app/console doctrine:schema:update --force --em=customer