diff --git a/src/Driver/AbstractPostgreSQLDriver.php b/src/Driver/AbstractPostgreSQLDriver.php index 099630d3368..b7e93c58bfc 100644 --- a/src/Driver/AbstractPostgreSQLDriver.php +++ b/src/Driver/AbstractPostgreSQLDriver.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQL100Platform; +use Doctrine\DBAL\Platforms\PostgreSQL120Platform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\PostgreSQLSchemaManager; @@ -40,6 +41,10 @@ public function createDatabasePlatformForVersion($version) $patchVersion = $versionParts['patch'] ?? 0; $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion; + if (version_compare($version, '12.0', '>=')) { + return new PostgreSQL120Platform(); + } + if (version_compare($version, '10.0', '>=')) { return new PostgreSQL100Platform(); } diff --git a/src/Platforms/PostgreSQL120Platform.php b/src/Platforms/PostgreSQL120Platform.php new file mode 100644 index 00000000000..9553f27d0ad --- /dev/null +++ b/src/Platforms/PostgreSQL120Platform.php @@ -0,0 +1,30 @@ +_platform->getDefaultColumnValueSQLSnippet(); + + $sql .= <<connection->getWrappedConnection(); + assert($wrappedConnection instanceof ServerInfoAwareConnection); + if (!$this->connection->getDatabasePlatform() instanceof PostgreSQL120Platform) { + self::markTestSkipped('Generated columns are not supported in Postgres 11 and earlier'); + } + + $table = new Table('ddc6198_generated_always_as'); + $table->addColumn('id', Types::INTEGER); + $table->addColumn( + 'idIsOdd', + Types::BOOLEAN, + ['columnDefinition' => 'boolean GENERATED ALWAYS AS (id % 2 = 1) STORED', 'notNull' => false], + ); + + $this->dropAndCreateTable($table); + + $databaseTable = $this->schemaManager->introspectTable($table->getName()); + + $diff = $comparatorFactory($this->schemaManager)->diffTable($table, $databaseTable); + + self::assertFalse($diff); + } + /** * PostgreSQL stores BINARY columns as BLOB */