Situation
I'm using Prooph for my commandbus, eventbus and eventstore within Symfony 4.3. Since not every aggregate needs to be eventsourced, we also use Doctrine DBAL to just simply CRUD those simple aggregates.
Within a given domain I have commands / handlers configured in my commandbus which use either eventsourced repositories OR DBAL repositories.
When injecting this commandbus into a CLI command this results in multiple db connections when running anything on the CLI.
Problem
When trying to delete/create the database (for pristine install or resetting the test environment) Postgres refuses because there is another active connection.
Could not drop database "api" for connection named default
An exception occurred while executing 'DROP DATABASE "api"':
SQLSTATE[55006]: Object in use: 7 ERROR: database "api" is being accessed by other users
DETAIL: There is 1 other session using the database.
- I tried disabling all commands which have an eventsourced repository and the problem is fixed.
- I tried disabling all commands which have a DBAL repository and the problem is fixed.
- I tried not injecting this commandbus and the problem is fixed.
So I can safely conclude that the problem rises when using services with a PDO connection in combination with services with a DBAL connection.
Solution (failed)
A solution I though of was to use the Doctrine DBAL $connection->getWrappedConnection()
for the Prooph Eventstore. Obviously typehinting does not allow this (getWrappedConnection()
returns a Connection
-interface) but the actual Doctrine PDOConnection
extends \PDO
should it does work, I'm willing to accept the hackiness at this point! However, to no avail, still 2 connections.