mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-23 08:06:33 +00:00
Merge pull request #3488 from wallabag/pg-10
Add custom driver & schema manager for PostgreSQL 10
This commit is contained in:
commit
70265817ae
8 changed files with 70 additions and 0 deletions
|
@ -47,6 +47,7 @@ twig:
|
|||
doctrine:
|
||||
dbal:
|
||||
driver: "%database_driver%"
|
||||
driver_class: "%database_driver_class%"
|
||||
host: "%database_host%"
|
||||
port: "%database_port%"
|
||||
dbname: "%database_name%"
|
||||
|
|
|
@ -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%"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
parameters:
|
||||
test_database_driver: pdo_sqlite
|
||||
test_database_driver_class: ~
|
||||
test_database_host: localhost
|
||||
test_database_port:
|
||||
test_database_name: ~
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
$sequenceName = $sequence['relname'];
|
||||
if ('public' !== $sequence['schemaname']) {
|
||||
$sequenceName = $sequence['schemaname'] . '.' . $sequence['relname'];
|
||||
}
|
||||
|
||||
$query = 'SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
$data = $this->_conn->fetchAll($query);
|
||||
|
||||
return new Sequence($sequenceName, $data[0]['increment_by'], $data[0]['min_value']);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue