diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 4888d2aa172..b7acf8266ce 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -163,7 +163,7 @@ jobs: php-version: - "8.0" postgres-version: - - "9.4" + - "10" - "13" - "14" include: diff --git a/UPGRADE.md b/UPGRADE.md index cd6cbf76a8f..d0038856c9c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -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 diff --git a/psalm.xml.dist b/psalm.xml.dist index 8df3c2d60e1..48f00adf6b0 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -46,11 +46,6 @@ is no longer supported. --> - - - diff --git a/src/Driver/AbstractPostgreSQLDriver.php b/src/Driver/AbstractPostgreSQLDriver.php index 7ff59438799..2c38a22c813 100644 --- a/src/Driver/AbstractPostgreSQLDriver.php +++ b/src/Driver/AbstractPostgreSQLDriver.php @@ -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. @@ -26,31 +21,6 @@ abstract class AbstractPostgreSQLDriver implements Driver { public function getDatabasePlatform(ServerVersionProvider $versionProvider): PostgreSQLPlatform { - $version = $versionProvider->getServerVersion(); - - if (preg_match('/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?/', $version, $versionParts) === 0) { - throw InvalidPlatformVersion::new( - $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(); } diff --git a/src/Platforms/Keywords/PostgreSQL100Keywords.php b/src/Platforms/Keywords/PostgreSQL100Keywords.php deleted file mode 100644 index 9e1c533bedd..00000000000 --- a/src/Platforms/Keywords/PostgreSQL100Keywords.php +++ /dev/null @@ -1,18 +0,0 @@ -quoteStringLiteral($database) . " - AND sequence_schema NOT LIKE 'pg\_%' - AND sequence_schema != 'information_schema'"; - } -} diff --git a/src/Platforms/PostgreSQLPlatform.php b/src/Platforms/PostgreSQLPlatform.php index d141b18795b..5565779beb2 100644 --- a/src/Platforms/PostgreSQLPlatform.php +++ b/src/Platforms/PostgreSQLPlatform.php @@ -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'"; } diff --git a/src/Schema/PostgreSQLSchemaManager.php b/src/Schema/PostgreSQLSchemaManager.php index 2b2edb8fe66..dd62dc248ae 100644 --- a/src/Schema/PostgreSQLSchemaManager.php +++ b/src/Schema/PostgreSQLSchemaManager.php @@ -20,7 +20,6 @@ use function preg_match; use function sprintf; use function str_replace; -use function strpos; use function strtolower; use function trim; @@ -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': @@ -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]+)\))', @@ -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 */ diff --git a/src/Tools/Console/Command/ReservedWordsCommand.php b/src/Tools/Console/Command/ReservedWordsCommand.php index 21b6bbe6a09..a8102dad3a1 100644 --- a/src/Tools/Console/Command/ReservedWordsCommand.php +++ b/src/Tools/Console/Command/ReservedWordsCommand.php @@ -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; @@ -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(), ]; @@ -103,7 +101,6 @@ protected function configure(): void * mysql80 * oracle * pgsql - * pgsql100 * sqlite * sqlserver EOT diff --git a/tests/Driver/AbstractPostgreSQLDriverTest.php b/tests/Driver/AbstractPostgreSQLDriverTest.php index 32ef4daa890..1fd50bd95ce 100644 --- a/tests/Driver/AbstractPostgreSQLDriverTest.php +++ b/tests/Driver/AbstractPostgreSQLDriverTest.php @@ -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; @@ -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); @@ -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], ]; } } diff --git a/tests/Platforms/PostgreSQL100PlatformTest.php b/tests/Platforms/PostgreSQL100PlatformTest.php deleted file mode 100644 index b6b524769b9..00000000000 --- a/tests/Platforms/PostgreSQL100PlatformTest.php +++ /dev/null @@ -1,31 +0,0 @@ -platform->getListSequencesSQL('test_db') - ); - } -} diff --git a/tests/Platforms/PostgreSQLPlatformTest.php b/tests/Platforms/PostgreSQLPlatformTest.php index 61b54e401e4..924bbe4fcab 100644 --- a/tests/Platforms/PostgreSQLPlatformTest.php +++ b/tests/Platforms/PostgreSQLPlatformTest.php @@ -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') + ); + } }