Symfony2: multiple DB / entity manager connections with doctrine and schema_filter migrations

I currently have one symfony2 (2.1) file management application for a database / entity that works fine, including doctrine migration. I'm in the process of adding a second database connection + entity manager, and I'm having problems migrating the doctrine to do what I want.

Essentially, I want most of my entities to live in my first database by default and have several new entities / tables in the second database, and then the doctrine migration controls any changes to the schemas. The documentation seems to imply that you can set "schema_filter" in the connection to achieve this.

(Usage example: there are several applications of our application for white intermediaries, each of which has its own main database. However, we are introducing online help, which will be written as a CMS / blog interface and accessible through this second database for all installations. )

So far, my doctrine configuration looks like this (from app / config / config.yml):

    dbal:
        default:
            driver:   %database_driver%
            host:     %database_host%
            port:     %database_port%
            dbname:   %database_name%
            user:     %database_user%
            password: %database_password%
            charset:  UTF8
            schema_filter: ~^(?!help_)~
        cross_site:
            driver:   %crossite_database_driver%
            host:     %crossite_database_host%
            port:     %crossite_database_port%
            dbname:   %crossite_database_name%
            user:     %crossite_database_user%
            password: %crossite_database_password%
            charset:  UTF8
            schema_filter: ~^help_~

orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            mappings:
                <most of the bundles>
        help:
            connection: cross_site
            mappings:
                HelpBundle: ~

The goal is to have most entities / tables in the database by default, but exclude any table starting with "help_". Conversely, the second database should contain only those tables starting with "help_".

However, whenever I start the doctrine migration using the entity manager, it will simply include all the tables regardless of their name.

php app/console doctrine:migrations:migrate # includes every table including help_*
php app/console doctrine:migrations:migrate --em="help" # includes every table

schema_filter? ?

: ... "help" , -em = "help"; :

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'migration_versions' already exists 

EM . ?

+4
1

, , ... , - .

  • doctrine: migrations: migrate more-or-less schema_filter. , , ... - SQL .
  • doctrine: migrations: diff, schema_filter. , schema_filter. diff, migrate, --em = [name].
  • migration_versions schema_filter. , , ( ).

, . schema_filter, migration_versions:

            cross_site: 
                schema_filter: ~^(help_|migration_versions)~

( /DoctrineMigrations ), /:

$this->skipIf( $this->connection->getDatabase() != '[second DB name]', 'Skipping help database.' );

, , , . , up(), down().

+6

All Articles