From a1661af17c9054a6c399dd9d5220f8d6a5091fa2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 12 Dec 2017 12:14:40 +0100 Subject: [PATCH] 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 ++++++++++++ .../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']); + } +} -- 2.41.0