具有单个连接和多个模式的Symfony和Doctrine灯具

时间:2016-02-14 16:03:07

标签: symfony doctrine fixtures

我使用Symfony和Doctrine灯具创建测试数据库。我们的应用程序具有单个数据库连接,具有3个模式和交叉模式关系。

我有3个软件包,每个软件包都有每个模式的实体类和夹具。我已经能够创建交叉捆绑关系但我在使用php bin / console doctrine:fixtures:load 加载灯具时遇到问题。理想情况下,我希望能够运行类似于以下的内容来设置我的测试数据库并进行拆解:

php bin/console doctrine:database:create
php bin/console doctrine:schema:create / php bin/console doctrine:schema:update
php bin/console doctrine:fixtures:load
php bin/console doctrine:database:drop

我的配置对于连接和实体管理器应该是什么样的?我是否需要为每个模式运行上述每个模式,如果我需要多个实体管理器,我的映射应该是什么样的?

数据库结构

- Database
   - Schema1
   - Schema2
   - Schema3

捆绑

- Acme
   - Bundle
      - Schema1Bundle
         - Entity
         - DataFixtures
             - ORM
      - Schema2Bundle
         - Entity
         - DataFixtures
             - ORM
      - Schema3Bundle
         - Entity
         - DataFixtures
             - ORM

Composer.json

"require": {
    "php": ">=5.5.9",
    "symfony/symfony": "3.0.*",
    "doctrine/orm": "^2.5",
    "doctrine/doctrine-bundle": "^1.6",
    "doctrine/doctrine-cache-bundle": "^1.2",
    "symfony/swiftmailer-bundle": "^2.3",
    "symfony/monolog-bundle": "^2.8",
    "sensio/distribution-bundle": "^5.0",
    "sensio/framework-extra-bundle": "^3.0.2",
    "incenteev/composer-parameter-handler": "^2.0",
    "symfony/console": "^3.0",
    "league/flysystem": "^1.0"
},
"require-dev": {
    "sensio/generator-bundle": "^3.0",
    "symfony/phpunit-bridge": "^2.7",
    "doctrine/doctrine-fixtures-bundle": "^2.3"
},

config.yml

orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: schema1

entity_managers:
    schema1:
        auto_mapping: false
        connection: schema1
        mappings:
            AcmeBundleSchema1Bundle: ~
            AcmeBundleSchema2Bundle: ~
            AcmeBundleSchema3Bundle: ~

示例xml映射:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Acme\Bundle\Schema1Bundle\Entity\Currency" table="schema1.currency">
  <id name="currencyCode" type="string" column="currency_code" length="3">
      <generator strategy="IDENTITY"/>
  </id>
  <field name="nsInternalId" type="integer" column="ns_internal_id" nullable="true">
      <options>
          <option name="unsigned">1</option>
      </options>
   </field>
   </entity>
</doctrine-mapping>

我尝试过使用多个实体管理器但是在加载fixture时,它会尝试在不正确的架构中截断表。

更新 当我运行doctrine时,我收到以下错误:fixtures:load --em = schema1

An exception occurred while executing 'DELETE FROM boosted_user':
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'schema1.user' doesn't exist

用户表在schema2中,但出于某种原因,当fixtures:load尝试删除现有记录时,它会尝试对所有表执行此操作。

我发现删除第141行记录时ORMPurger.php不使用架构:

$this->em->getConnection()->executeUpdate("DELETE FROM " . $tbl);

0 个答案:

没有答案