2

Using Symfony 2.5 and Doctrine 2.2, I have several databases for an application I'm working on, let's call one "Main" and the other "Secondary". There are currently two entity managers configured. In one migration I want to create a table in "Secondary" but it only wants to create the table in "Main."

A migration can be ContainerAware, so I can get another EntityManager, but I have been unable to override the default one. Any able to help? Thanks in advance!

b.b3rn4rd
  • 8,494
  • 2
  • 45
  • 57
fwallen
  • 58
  • 1
  • 7

1 Answers1

2

Just pass --em parameter when generating diff.

Example:

php app/console doctrine:migrations:diff --em=uac # will use uac entity manager
php app/console doctrine:migrations:diff # will use the default entity manager

To exclude custom tables from removal use:

doctrine:
    dbal:
        schema_filter: ~^(?!t_)~

as per this document, alternatively you can pass filter argument at the runtime:

app/console doctrine:migrations:diff  --em=uac --filter-expression=/whatever/
b.b3rn4rd
  • 8,494
  • 2
  • 45
  • 57
  • if i have two entity manager lets say `identity` and `catalog` identity will create users table catalog will create course related tables but when running the migration:diff --em=catalog the users table is getting dropped. how to solve that? – Jaime Sangcap Feb 04 '15 at 12:35
  • @Daskul, do you store all tables in one database, usually when ppl have multiple entity managers they also have multiple databases ? – b.b3rn4rd Feb 04 '15 at 22:16
  • i only have one database. I am using different entity manager on different system or context. like on one context I have `Client` class which maps to `clients` table. on the other context I have `Inquirer` class which maps to `clients` table also but only needs fewer columns than the `Client` class – Jaime Sangcap Feb 05 '15 at 05:31
  • yeah, migration does what it supposed to do, however, you can exclude tables from `diff` as suggested in this doc : `http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html#manual-tables` If can also filter tables at `diff` runtime by passing `--filter-expression=` argument – b.b3rn4rd Feb 05 '15 at 07:01
  • I read about that, but I was hoping for better solution, I dont want to think about the regex everytime I will do migration. I am thinking of creating something like `migrations` entity manager which its only purpose is for migration. my problem is I am adding the mapping on per directory on `config.yml` which causes errors mapping again one table on multiple entity. (ex. I have directory Catalog/ and Inquiry/ ) i have entity on each directory that maps to `clients` table. Is there a way to exclude the entity on the other directory to avoid collision? – Jaime Sangcap Feb 05 '15 at 07:16