Skip to content

Commit

Permalink
Drop support for Postgres 9
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Dec 2, 2021
1 parent cc76199 commit 3e18682
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
php-version:
- "8.0"
postgres-version:
- "9.4"
- "10"
- "13"
- "14"
include:
Expand Down
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ awareness about deprecated code.

# Upgrade to 4.0

## BC BREAK: Removed active support for Postgres 9

Postgres 9 is not actively supported anymore. The following classes have been merged into their respective parent class:

* `Doctrine\DBAL\Platforms\PostgreSQL100Platform`
* `Doctrine\DBAL\Platforms\Keywords\PostgreSQL100Keywords`

## BC BREAK: Removed Platform "commented type" API

Since `Type::requiresSQLCommentTypeHint()` already allows determining whether a
Expand Down
5 changes: 0 additions & 5 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
is no longer supported.
-->
<file name="src/Tools/Console/ConsoleRunner.php"/>
<!--
TODO: remove in 4.0.0
-->
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\PostgreSQL100Keywords"/>
<referencedClass name="Doctrine\DBAL\Platforms\PostgreSQL100Platform"/>
</errorLevel>
</DeprecatedClass>
<DeprecatedMethod>
Expand Down
30 changes: 0 additions & 30 deletions src/Driver/AbstractPostgreSQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\PostgreSQL\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\PostgreSQLSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;
use Doctrine\Deprecations\Deprecation;

use function assert;
use function preg_match;
use function version_compare;

/**
* Abstract base implementation of the {@link Driver} interface for PostgreSQL based drivers.
Expand All @@ -26,31 +21,6 @@ abstract class AbstractPostgreSQLDriver implements Driver
{
public function getDatabasePlatform(ServerVersionProvider $versionProvider): PostgreSQLPlatform
{
$version = $versionProvider->getServerVersion();

if (preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts) === 0) {
throw InvalidPlatformVersion::new(
$version,
'<major_version>.<minor_version>.<patch_version>'
);
}

$majorVersion = $versionParts['major'];
$minorVersion = $versionParts['minor'] ?? 0;
$patchVersion = $versionParts['patch'] ?? 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;

if (version_compare($version, '10.0', '>=')) {
return new PostgreSQL100Platform();
}

Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5060',
'PostgreSQL 9 support is deprecated and will be removed in DBAL 4.'
. ' Consider upgrading to Postgres 10 or later.'
);

return new PostgreSQLPlatform();
}

Expand Down
18 changes: 0 additions & 18 deletions src/Platforms/Keywords/PostgreSQL100Keywords.php

This file was deleted.

34 changes: 0 additions & 34 deletions src/Platforms/PostgreSQL100Platform.php

This file was deleted.

9 changes: 6 additions & 3 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,13 @@ public function getListDatabasesSQL(): string

public function getListSequencesSQL(string $database): string
{
return "SELECT sequence_name AS relname,
sequence_schema AS schemaname
return 'SELECT sequence_name AS relname,
sequence_schema AS schemaname,
minimum_value AS min_value,
increment AS increment_by
FROM information_schema.sequences
WHERE sequence_schema NOT LIKE 'pg\_%'
WHERE sequence_catalog = ' . $this->quoteStringLiteral($database) . "
AND sequence_schema NOT LIKE 'pg\_%'
AND sequence_schema != 'information_schema'";
}

Expand Down
26 changes: 1 addition & 25 deletions src/Schema/PostgreSQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use function preg_match;
use function sprintf;
use function str_replace;
use function strpos;
use function strtolower;
use function trim;

Expand Down Expand Up @@ -328,21 +327,12 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
switch ($dbType) {
case 'smallint':
case 'int2':
$tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']);
$length = null;
break;

case 'int':
case 'int4':
case 'integer':
$tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']);
$length = null;
break;

case 'bigint':
case 'int8':
$tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']);
$length = null;
$length = null;
break;

case 'bool':
Expand Down Expand Up @@ -378,8 +368,6 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
case 'decimal':
case 'money':
case 'numeric':
$tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']);

if (
preg_match(
'([A-Za-z]+\(([0-9]+),([0-9]+)\))',
Expand Down Expand Up @@ -442,18 +430,6 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
return $column;
}

/**
* PostgreSQL 9.4 puts parentheses around negative numeric default values that need to be stripped eventually.
*/
private function fixVersion94NegativeNumericDefaultValue(mixed $defaultValue): mixed
{
if ($defaultValue !== null && strpos($defaultValue, '(') === 0) {
return trim($defaultValue, '()');
}

return $defaultValue;
}

/**
* Parses a default value expression as given by PostgreSQL
*/
Expand Down
3 changes: 0 additions & 3 deletions src/Tools/Console/Command/ReservedWordsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Doctrine\DBAL\Platforms\Keywords\MySQL80Keywords;
use Doctrine\DBAL\Platforms\Keywords\MySQLKeywords;
use Doctrine\DBAL\Platforms\Keywords\OracleKeywords;
use Doctrine\DBAL\Platforms\Keywords\PostgreSQL100Keywords;
use Doctrine\DBAL\Platforms\Keywords\PostgreSQLKeywords;
use Doctrine\DBAL\Platforms\Keywords\ReservedKeywordsValidator;
use Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords;
Expand Down Expand Up @@ -53,7 +52,6 @@ public function __construct(ConnectionProvider $connectionProvider)
'mysql80' => new MySQL80Keywords(),
'oracle' => new OracleKeywords(),
'pgsql' => new PostgreSQLKeywords(),
'pgsql100' => new PostgreSQL100Keywords(),
'sqlite' => new SQLiteKeywords(),
'sqlserver' => new SQLServerKeywords(),
];
Expand Down Expand Up @@ -103,7 +101,6 @@ protected function configure(): void
* mysql80
* oracle
* pgsql
* pgsql100
* sqlite
* sqlserver
EOT
Expand Down
13 changes: 8 additions & 5 deletions tests/Driver/AbstractPostgreSQLDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\API\PostgreSQL;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\PostgreSQLSchemaManager;
Expand All @@ -20,6 +19,11 @@
*/
class AbstractPostgreSQLDriverTest extends AbstractDriverTest
{
public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion(): void
{
self::markTestSkipped('PostgreSQL drivers do not use server version to instantiate platform');
}

protected function createDriver(): Driver
{
return $this->getMockForAbstractClass(AbstractPostgreSQLDriver::class);
Expand Down Expand Up @@ -49,10 +53,9 @@ protected function createExceptionConverter(): ExceptionConverter
public static function platformVersionProvider(): array
{
return [
['9.4', PostgreSQLPlatform::class],
['9.4.0', PostgreSQLPlatform::class],
['9.4.1', PostgreSQLPlatform::class],
['10', PostgreSQL100Platform::class],
['10.0', PostgreSQLPlatform::class],
['11.0', PostgreSQLPlatform::class],
['13.3', PostgreSQLPlatform::class],
];
}
}
31 changes: 0 additions & 31 deletions tests/Platforms/PostgreSQL100PlatformTest.php

This file was deleted.

15 changes: 15 additions & 0 deletions tests/Platforms/PostgreSQLPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1027,4 +1027,19 @@ public function testInitializesJsonTypeMapping(): void
self::assertTrue($this->platform->hasDoctrineTypeMappingFor('jsonb'));
self::assertEquals(Types::JSON, $this->platform->getDoctrineTypeMapping('jsonb'));
}

public function testGetListSequencesSQL(): void
{
self::assertSame(
"SELECT sequence_name AS relname,
sequence_schema AS schemaname,
minimum_value AS min_value,
increment AS increment_by
FROM information_schema.sequences
WHERE sequence_catalog = 'test_db'
AND sequence_schema NOT LIKE 'pg\_%'
AND sequence_schema != 'information_schema'",
$this->platform->getListSequencesSQL('test_db')
);
}
}

0 comments on commit 3e18682

Please sign in to comment.