diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-12-12 12:14:40 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-12-12 12:14:40 +0100 |
commit | a1661af17c9054a6c399dd9d5220f8d6a5091fa2 (patch) | |
tree | 126a64f79b8b840b9b4c2b876f4da64eb5dc3f03 /src | |
parent | f209798368de66b4acd8b892fe71018ebb30c2da (diff) | |
download | wallabag-a1661af17c9054a6c399dd9d5220f8d6a5091fa2.tar.gz wallabag-a1661af17c9054a6c399dd9d5220f8d6a5091fa2.tar.zst wallabag-a1661af17c9054a6c399dd9d5220f8d6a5091fa2.zip |
Add custom driver & schema manager for PostgreSQL 10
Diffstat (limited to 'src')
-rw-r--r-- | src/Wallabag/CoreBundle/Doctrine/DBAL/Driver/CustomPostgreSQLDriver.php | 25 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php | 38 |
2 files changed, 63 insertions, 0 deletions
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 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Doctrine\DBAL\Driver; | ||
4 | |||
5 | use Doctrine\DBAL\Connection; | ||
6 | use Doctrine\DBAL\Driver\PDOPgSql\Driver; | ||
7 | use Wallabag\CoreBundle\Doctrine\DBAL\Schema\CustomPostgreSqlSchemaManager; | ||
8 | |||
9 | /** | ||
10 | * This custom driver allow to use a different schema manager | ||
11 | * So we can fix the PostgreSQL 10 problem. | ||
12 | * | ||
13 | * @see https://github.com/wallabag/wallabag/issues/3479 | ||
14 | * @see https://github.com/doctrine/dbal/issues/2868 | ||
15 | */ | ||
16 | class CustomPostgreSQLDriver extends Driver | ||
17 | { | ||
18 | /** | ||
19 | * {@inheritdoc} | ||
20 | */ | ||
21 | public function getSchemaManager(Connection $conn) | ||
22 | { | ||
23 | return new CustomPostgreSqlSchemaManager($conn); | ||
24 | } | ||
25 | } | ||
diff --git a/src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php b/src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php new file mode 100644 index 00000000..b49166f2 --- /dev/null +++ b/src/Wallabag/CoreBundle/Doctrine/DBAL/Schema/CustomPostgreSqlSchemaManager.php | |||
@@ -0,0 +1,38 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Doctrine\DBAL\Schema; | ||
4 | |||
5 | use Doctrine\DBAL\Schema\PostgreSqlSchemaManager; | ||
6 | use Doctrine\DBAL\Schema\Sequence; | ||
7 | |||
8 | /** | ||
9 | * This custom schema manager fix the PostgreSQL 10 problem. | ||
10 | * | ||
11 | * @see https://github.com/wallabag/wallabag/issues/3479 | ||
12 | * @see https://github.com/doctrine/dbal/issues/2868 | ||
13 | */ | ||
14 | class CustomPostgreSqlSchemaManager extends PostgreSqlSchemaManager | ||
15 | { | ||
16 | /** | ||
17 | * {@inheritdoc} | ||
18 | */ | ||
19 | protected function _getPortableSequenceDefinition($sequence) | ||
20 | { | ||
21 | if ('public' !== $sequence['schemaname']) { | ||
22 | $sequenceName = $sequence['schemaname'] . '.' . $sequence['relname']; | ||
23 | } else { | ||
24 | $sequenceName = $sequence['relname']; | ||
25 | } | ||
26 | |||
27 | $query = 'SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName); | ||
28 | |||
29 | // patch for PostgreSql >= 10 | ||
30 | if ((float) ($this->_conn->getWrappedConnection()->getServerVersion()) >= 10) { | ||
31 | $query = "SELECT min_value, increment_by FROM pg_sequences WHERE schemaname = 'public' AND sequencename = " . $this->_conn->quote($sequenceName); | ||
32 | } | ||
33 | |||
34 | $data = $this->_conn->fetchAll($query); | ||
35 | |||
36 | return new Sequence($sequenceName, $data[0]['increment_by'], $data[0]['min_value']); | ||
37 | } | ||
38 | } | ||