Fix DoctrineDriver for postgreSQL #275
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DoctrineDrivercurrently has this implementationWhile this works for most of the DB vendors, it does not work for PostgreSQL 9.5. As soon as I produce an event I receive the following error:
This error is triggered by postgreSQL itself when he sees that you are in a transaction, something failed and you still try to use the same connection (in that transaction) to do queries (in this case we're trying to do the
INSERT INTO bernard_messagesafter a failedINSERT INTO bernard_queuesdue to duplicate key)Note that the error refers to
INSERT INTO bernard_messagesnot because it's the problem, but just because postgreSQL stops us to do something on a "broken" transaction (and it became broken after trying to insert a row with an already existent key onbernard_queues).PostgreSQL version used:
My proposed solution is to remove the try-catch and add a doctrine-driver specific method that checks the existence of such queue name before trying to insert it.
NOTE: It adds 1 query (on a primary key) per event produced, if we think that it's not acceptable we could cache the result executing at most 1 query per queue (or we could push further using only 1 query if we pre-fill the cache)