-
-
Notifications
You must be signed in to change notification settings - Fork 461
Description
Bug Report
Q | A |
---|---|
Version | 2.13.2 |
Previous Version if the bug is a regression | N/A |
Summary
Schema filters are only registered for the default connection on multi-connection setups.
For example, combining this with the migrations bundle, the doctrine_migration_versions
table is only filtered out of e.g. doctrine:schema:drop
for the default_connection in a setup with multiple entity managers and multiple migration configurations. This causes implicit (and depending on the filters, potentially destructive) behaviour.
Current behavior
The \Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DbalSchemaFilterPass
registers schema filters (like \Doctrine\Bundle\MigrationsBundle\EventListener\SchemaFilterListener
) only for the connection referred to by default_connection.
Expected behavior
Schema filters should be applied to every connection when tagged appropriately in the container.
How to reproduce
Configuring Symfony's doctrine.yaml as follows (snippet from our configuration with modified naming):
doctrine:
dbal:
connections:
database1:
dbname: '%env(DATABASE_SCHEMA_DATABASE1)%'
# Common parameters
host: '%env(string:default:database.fallback_host:DATABASE_RDS_HOST)%'
user: '%env(DATABASE_USERNAME)%'
password: '%env(DATABASE_PASSWORD)%'
port: '%env(DATABASE_PORT)%'
driver: 'pdo_mysql'
server_version: '%env(DATABASE_SERVER_VERSION)%'
charset: 'utf8mb4'
profiling_collect_backtrace: '%kernel.debug%'
use_savepoints: true
default_table_options:
charset: 'utf8mb4'
collation: 'utf8mb4_general_ci'
engine: 'InnoDB'
database2:
dbname: '%env(DATABASE_SCHEMA_DATABASE2)%'
# Common parameters
host: '%env(string:default:database.fallback_host:DATABASE_RDS_HOST)%'
user: '%env(DATABASE_USERNAME)%'
password: '%env(DATABASE_PASSWORD)%'
port: '%env(DATABASE_PORT)%'
driver: 'pdo_mysql'
server_version: '%env(DATABASE_SERVER_VERSION)%'
charset: 'utf8mb4'
profiling_collect_backtrace: '%kernel.debug%'
use_savepoints: true
default_table_options:
charset: 'utf8mb4'
collation: 'utf8mb4_general_ci'
engine: 'InnoDB'
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
controller_resolver:
enabled: false
auto_mapping: false
entity_managers:
database1:
connection: database1
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: false
mappings:
App:
type: attribute
is_bundle: false
dir: '%kernel.project_dir%/src/Database1/Domain/Entity'
prefix: 'App\Database1\Domain\Entity'
alias: AppDatabase1
database2:
connection: database2
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: false
mappings:
Domain:
type: attribute
is_bundle: false
dir: '%kernel.project_dir%/src/Database2/Domain/Entity'
prefix: 'App\Database2\Domain\Entity'
alias: AppDatabase2
Results in the following output for the different databases.
Assuming:
database1
has tablesabc
anddoctrine_migration_versions
database2
has tablesdef
anddoctrine_migration_versions
Running bin/console doctrine:schema:drop --dump-sql --full-database --em=database1
yields:
DROP TABLE abc;
Running bin/console doctrine:schema:drop --dump-sql --full-database --em=database2
yields:
DROP TABLE def;
DROP TABLE doctrine_migration_versions;
Note the absence of doctrine_migration_versions in the case of database1, because it is automatically selected as default_connection by the Doctrine bundle and thus the filter is applied.