-
-
Notifications
You must be signed in to change notification settings - Fork 397
Description
Bug Report
| Q | A |
|---|---|
| BC Break | no |
| Version | latest |
Summary
DbalExecutor in doctrine/migrations uses Connection::executeQuery for executing SQL statements, including write operations. However, PrimaryReadReplicaConnection in doctrine/dbal expects executeQuery to be used only for read operations. This can result in write queries being sent to replica nodes, causing data inconsistency.
Current behavior
When running migrations, DbalExecutor calls executeQuery for all SQL statements, including writes (e.g., INSERT, UPDATE, DELETE, DDL). If the connection is configured as PrimaryReadReplicaConnection, these write operations may be executed on a replica instead of the primary.
How to reproduce
- Configure Doctrine DBAL with PrimaryReadReplicaConnection and at least one replica.
- Run a migration that performs a write operation (e.g., creates a table or inserts data).
- Observe that the write query is executed using executeQuery, which may target a replica.
Expected behavior
Write operations in migrations should use executeStatement to ensure they are always executed on the primary node, as per the contract of PrimaryReadReplicaConnection. Only read operations should use executeQuery.