]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add custom driver & schema manager for PostgreSQL 10
authorJeremy Benoist <jeremy.benoist@gmail.com>
Tue, 12 Dec 2017 11:14:40 +0000 (12:14 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Tue, 12 Dec 2017 11:14:40 +0000 (12:14 +0100)
app/config/config.yml
app/config/config_test.yml
app/config/parameters.yml.dist
app/config/tests/parameters_test.mysql.yml
app/config/tests/parameters_test.pgsql.yml
app/config/tests/parameters_test.sqlite.yml
src/Wallabag/CoreBundle/Doctrine/DBAL/Driver/CustomPostgreSQLDriver.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php [new file with mode: 0644]

index 08da4f8f8bb8e11948cff4355e8924e083734462..04d757c1f3b9cbf87f0db517e23ee69c5f790f0b 100644 (file)
@@ -47,6 +47,7 @@ twig:
 doctrine:
     dbal:
         driver: "%database_driver%"
+        driver_class: "%database_driver_class%"
         host: "%database_host%"
         port: "%database_port%"
         dbname: "%database_name%"
index c620c35995c3afb97febcfeecf1d3e72191a263e..fc067ff46892d2cf646f5dbad992d4d96574771b 100644 (file)
@@ -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%"
index b5b97950cac10d4198a4475bfa388888f8325828..6b0cb8e84c9c5aa23d4cbd1035e8cfce8bbf07b8 100644 (file)
@@ -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
index 36b227fbc800f11ce6dbebb0a9d8eade68d728be..0b7b82eb922cd7686bc970e766e099b9952116b8 100644 (file)
@@ -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
index 60f51df6d84e0c6631d15de618726bd294c4acfd..ea249324e0eff08518a1ba52c27ae4e391b25b71 100644 (file)
@@ -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
index 2b92d579f5d1db332c3aa68c523734c15e94043c..64cd984b9c01d74b911f7a32796c69bd12b0ba76 100644 (file)
@@ -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 (file)
index 0000000..eb5b203
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+namespace Wallabag\CoreBundle\Doctrine\DBAL\Driver;
+
+use Doctrine\DBAL\Connection;
+use Doctrine\DBAL\Driver\PDOPgSql\Driver;
+use Wallabag\CoreBundle\Doctrine\DBAL\Schema\CustomPostgreSqlSchemaManager;
+
+/**
+ * This custom driver allow to use a different schema manager
+ * So we can fix the PostgreSQL 10 problem.
+ *
+ * @see https://github.com/wallabag/wallabag/issues/3479
+ * @see https://github.com/doctrine/dbal/issues/2868
+ */
+class CustomPostgreSQLDriver extends Driver
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function getSchemaManager(Connection $conn)
+    {
+        return new CustomPostgreSqlSchemaManager($conn);
+    }
+}
diff --git a/src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php b/src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php
new file mode 100644 (file)
index 0000000..b49166f
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+namespace Wallabag\CoreBundle\Doctrine\DBAL\Schema;
+
+use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;
+use Doctrine\DBAL\Schema\Sequence;
+
+/**
+ * This custom schema manager fix the PostgreSQL 10 problem.
+ *
+ * @see https://github.com/wallabag/wallabag/issues/3479
+ * @see https://github.com/doctrine/dbal/issues/2868
+ */
+class CustomPostgreSqlSchemaManager extends PostgreSqlSchemaManager
+{
+    /**
+     * {@inheritdoc}
+     */
+    protected function _getPortableSequenceDefinition($sequence)
+    {
+        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) {
+            $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']);
+    }
+}