Postgres update with Doctrine issues

Thomas P
2 min readNov 30, 2018

--

How to update your postgres version without updating all your Symfony project deps.

Symfony 2.8 is a long term support version with security fix until november 2019. That’s why we still have in production projects using this version of Symfony. Perhaps, just like me, your stack architecture with micro-services may require a new version of Postgres, like the 10.5.

And so you have an issue like this when trying to update or validate or create a schema diff with doctrine:

SQLSTATE[42703]: Undefined column: 7 ERROR: column “min_value” does not exist
LINE 1: SELECT min_value, increment_by FROM “collection_user_id_seq”

This is a well know issue referenced in this issue (https://github.com/doctrine/dbal/issues/3139) and fixed there: https://github.com/doctrine/dbal/blob/83b72c1d85ce4dbe12525b646b1794ddfaa2c140/lib/Doctrine/DBAL/Platforms/PostgreSQL100Platform.php

To fix this, you need doctrine/dbal 2.7 at least. And trying to update doctrine/dbal can require an update of doctrine/orm, and munch more!

Composer PANIC!

I’ve see an Open source cloud project fixing this by forking doctrine/dbal to insert their fix. I don’t like this solution so I’ve search another way to fix this.

So here’s a solution to fix it:

Create a PDOPgSqlDriver in your project and define it has your own database driver in doctrine.yml:

doctrine:
dbal:
driver_class: App\Doctrine\Driver\PDOPgSqlDriver

Here’s the content of this driver. It’s a minimal driver extending Postgres previous version driver overriding two methods that return files you will need in your project too.

Your Postgres10SqlSchemaManager should only have one method:

And now create the PostgreSQL100Platform that will extends the previous PostgreSQLXXXPlatform you have in your dbal version.

Important step after adding thoses files in your project, is to help doctrine with the server_version:

doctrine:
dbal:
server_version: '10.5'

And now, let’s have fun with your project!

Follow me on twitter @scullwm

--

--

Thomas P
Thomas P

Written by Thomas P

Symfony lover, Gopher and opensource enthusiast. Ex-firefighter 🚒, I miss cuting out cars 🚙.

Responses (3)