From a1661af17c9054a6c399dd9d5220f8d6a5091fa2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 12 Dec 2017 12:14:40 +0100 Subject: Add custom driver & schema manager for PostgreSQL 10 --- app/config/config.yml | 1 + app/config/config_test.yml | 1 + app/config/parameters.yml.dist | 2 ++ app/config/tests/parameters_test.mysql.yml | 1 + app/config/tests/parameters_test.pgsql.yml | 1 + app/config/tests/parameters_test.sqlite.yml | 1 + .../DBAL/Driver/CustomPostgreSQLDriver.php | 25 ++++++++++++++ .../DBAL/Schema/CustomPostgreSqlSchemaManager.php | 38 ++++++++++++++++++++++ 8 files changed, 70 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Doctrine/DBAL/Driver/CustomPostgreSQLDriver.php create mode 100644 src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php diff --git a/app/config/config.yml b/app/config/config.yml index 08da4f8f..04d757c1 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -47,6 +47,7 @@ twig: doctrine: dbal: driver: "%database_driver%" + driver_class: "%database_driver_class%" host: "%database_host%" port: "%database_port%" dbname: "%database_name%" diff --git a/app/config/config_test.yml b/app/config/config_test.yml index c620c359..fc067ff4 100644 --- a/app/config/config_test.yml +++ b/app/config/config_test.yml @@ -23,6 +23,7 @@ swiftmailer: doctrine: dbal: driver: "%test_database_driver%" + driver_class: "%test_database_driver_class%" host: "%test_database_host%" port: "%test_database_port%" dbname: "%test_database_name%" diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index b5b97950..6b0cb8e8 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -11,6 +11,8 @@ parameters: # database_password: %env.database_password% database_driver: pdo_mysql + database_driver_class: ~ + # database_driver_class: Wallabag\CoreBundle\Doctrine\DBAL\Driver\CustomPostgreSQLDriver database_host: 127.0.0.1 database_port: ~ database_name: wallabag diff --git a/app/config/tests/parameters_test.mysql.yml b/app/config/tests/parameters_test.mysql.yml index 36b227fb..0b7b82eb 100644 --- a/app/config/tests/parameters_test.mysql.yml +++ b/app/config/tests/parameters_test.mysql.yml @@ -1,5 +1,6 @@ parameters: test_database_driver: pdo_mysql + test_database_driver_class: ~ test_database_host: localhost test_database_port: 3306 test_database_name: wallabag_test diff --git a/app/config/tests/parameters_test.pgsql.yml b/app/config/tests/parameters_test.pgsql.yml index 60f51df6..ea249324 100644 --- a/app/config/tests/parameters_test.pgsql.yml +++ b/app/config/tests/parameters_test.pgsql.yml @@ -1,5 +1,6 @@ parameters: test_database_driver: pdo_pgsql + test_database_driver_class: Wallabag\CoreBundle\Doctrine\DBAL\Driver\CustomPostgreSQLDriver test_database_host: localhost test_database_port: test_database_name: wallabag_test diff --git a/app/config/tests/parameters_test.sqlite.yml b/app/config/tests/parameters_test.sqlite.yml index 2b92d579..64cd984b 100644 --- a/app/config/tests/parameters_test.sqlite.yml +++ b/app/config/tests/parameters_test.sqlite.yml @@ -1,5 +1,6 @@ parameters: test_database_driver: pdo_sqlite + test_database_driver_class: ~ test_database_host: localhost test_database_port: test_database_name: ~ diff --git a/src/Wallabag/CoreBundle/Doctrine/DBAL/Driver/CustomPostgreSQLDriver.php b/src/Wallabag/CoreBundle/Doctrine/DBAL/Driver/CustomPostgreSQLDriver.php new file mode 100644 index 00000000..eb5b203f --- /dev/null +++ b/src/Wallabag/CoreBundle/Doctrine/DBAL/Driver/CustomPostgreSQLDriver.php @@ -0,0 +1,25 @@ +_platform->quoteIdentifier($sequenceName); + + // patch for PostgreSql >= 10 + if ((float) ($this->_conn->getWrappedConnection()->getServerVersion()) >= 10) { + $query = "SELECT min_value, increment_by FROM pg_sequences WHERE schemaname = 'public' AND sequencename = " . $this->_conn->quote($sequenceName); + } + + $data = $this->_conn->fetchAll($query); + + return new Sequence($sequenceName, $data[0]['increment_by'], $data[0]['min_value']); + } +} -- cgit v1.2.3 From 2e9747a59a6011622588829e4605af3710b61a21 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 12 Dec 2017 13:34:06 +0100 Subject: Fix tests --- .../Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php b/src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php index b49166f2..439ae17d 100644 --- a/src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php +++ b/src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php @@ -18,16 +18,16 @@ class CustomPostgreSqlSchemaManager extends PostgreSqlSchemaManager */ protected function _getPortableSequenceDefinition($sequence) { + $sequenceName = $sequence['relname']; if ('public' !== $sequence['schemaname']) { $sequenceName = $sequence['schemaname'] . '.' . $sequence['relname']; - } else { - $sequenceName = $sequence['relname']; } $query = 'SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName); - // patch for PostgreSql >= 10 - if ((float) ($this->_conn->getWrappedConnection()->getServerVersion()) >= 10) { + // the `method_exists` is only to avoid test to fail: + // DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticConnection doesn't support the `getServerVersion` + if (method_exists($this->_conn->getWrappedConnection(), 'getServerVersion') && (float) ($this->_conn->getWrappedConnection()->getServerVersion()) >= 10) { $query = "SELECT min_value, increment_by FROM pg_sequences WHERE schemaname = 'public' AND sequencename = " . $this->_conn->quote($sequenceName); } -- cgit v1.2.3