RedactedProfile
RedactedProfile

Reputation: 2808

Multiple Databases, One Doctrine Connection, and the one disobedient bundle

Weird issue I'm having with Doctrine ORM

I have various bundles that all contain their own set of entities that all manage their own databases. They are all managed under the same default connection.

# Doctrine Configuration
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   pdo_mysql
                host:     "%database_host%"
                port:     "%database_port%"
                user:     "%database_user%"
                password: "%database_password%"
                dbname:   "%database_dbname%"
                charset:  UTF8
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

As all of the managed databases share the same connection, the dbname parameter is intentionally left blank, and targeting the appropriate databases and the tables falls on me to specify in the @Table annotation.

My problem is that only two of the three bundles works anymore.

For sake of brevity the bundles are: AppBundle, BlogBundle, SalesBundle Each of those manages their own set of entities under {BundleName}\Entity. The setup is super simple, I will share the header of an entity from each bundle

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Account
 *
 * @ORM\Table(name="siteengine.account", options={"comment":"Governing User Account Storage"})
 * @ORM\Entity
 */
class Account
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

That one works.

<?php

namespace SalesBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Client
 *
 * @ORM\Entity(repositoryClass="SalesBundle\Repository\ClientRepository")
 * @ORM\Table(name="sales.Client", options={"comment":"Main/Primary Client Storage for Sales"})
 */
class Client
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

That one also works.

<?php

namespace BlogBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Entity\Account;

/**
 * @ORM\Entity(repositoryClass="BlogBundle\Repository\PostRepository")
 * @ORM\Table(name="blog.posts", options={"comment":"Primary Blog Post Storage"})
 */
class Post
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

This one does not.

And what I mean by "does not" is the doctrine commands. I can use the Blog entities anywhere, and get back the data I want and need, but I have to manually create the tables and schema myself for the blog entities in order to test this. For whatever reason, App and Sales bundles are working fine, any changes I make to them get reflected in the bin/console doctrine:schema:update --dump-sql outpu, but at no time, ever, does anything regarding the blog bundle get reflected in that same output.

Again, all under the same connection, two of the three bundles works with the schema tool, but all three bundles work when executing DQL commands.

I feel like, im losing my mind here

Upvotes: 0

Views: 1075

Answers (1)

RedactedProfile
RedactedProfile

Reputation: 2808

I found a solution. And I'm not a fan of the result.

After some more playing around, I noticed if I setup my default connection dbname parameter to any one of the databases, and run the command it will indeed sync up. Including the blog database.

I then stumbled upon a github project that is attempting to do exactly the same thing as me, and the Documentation shocked me there too as it confirmed a suspicion

  • Create the two test databases 'symfonydemo_post' and 'symfonydemo_user';
  • You can build the databases automatically, simply set the db name in parameters.yml to 'symfonydemo_post' and run 'php app/console doctrine:schema:update' to create the tables, change the db name to 'symfonydemo_user' and repeat the process to build the tables for the User entity.

Whelp.. I guess thats cool that you can have a little bit of control over the cli..........................................

Upvotes: 1

Related Questions