I am trying to setup a second database for a symfony 4.2 project. Everything seems to working fine up until the point where I run migrations where all migrations execute on the given connection instead of only the migrations for the connection it was created.
Following symfony's own documentation about this, my doctrine.yaml looks like this:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(DATABASE_URL)%'
logging:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(DATABASE_URL_LOG)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: default
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
logging:
connection: logging
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: false
mappings:
Log:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Log'
prefix: 'App\Log'
alias: Log
Now with this configuration I am able to run the migration commands with the --em=log/default parameter like this:
php bin/console doctrine:migrations:diff --em=log
php bin/console doctrine:migrations:migrate --em=log
And you get the expected results: It only creates a new migration for a new entity I created at src/Log when I add --em=log.
this is the new entity:
<?php
namespace App\Log;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
class LogItem
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
}
However, the migration is created in the default src/Migrations folder and as a result:
1) this migration is also executed when I run doctrine:migrations:migrate --em=default
(creating the table in the default database)
2) the entire default schema is loaded into the log database when I run doctrine:migrations:migrate --em=log
So I think the solution would be to split the migration files between the to entity managers into different directories. But I have been spending hours and can't find the way to do this for symfony4. Also, since the symfony documentation mentions absolutely nothing about this I feel like maybe something is wrong in the way it is setup now.
So can anyone tell me what I am doing wrong here? Or can (and if yes: how) do I split the migration files so it will only execute the migrations created for the given entity manager?