diff --git a/docs/en/reference/configuration.rst b/docs/en/reference/configuration.rst index bae6a1b35e..36fd39cc56 100644 --- a/docs/en/reference/configuration.rst +++ b/docs/en/reference/configuration.rst @@ -227,6 +227,7 @@ pdo_mysql - ``dbname`` (string): Name of the database/schema to connect to. - ``unix_socket`` (string): Name of the socket used to connect to the database. +- ``persistent`` (boolean): Whether to establish a persistent connection. - ``charset`` (string): The charset used when connecting to the database. @@ -283,6 +284,7 @@ pdo_pgsql / pgsql See `www.postgresql.org/docs/9.4/static/libpq-connect.html#LIBPQ-CONNECT-SSLCRL `_ - ``gssencmode`` (string): Optional GSS-encrypted channel/GSSEncMode configuration. See `www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-GSSENCMODE `_ +- ``persistent`` (boolean): Whether to establish a persistent connection (currently supported only by ``pdo_pgsql``). - ``application_name`` (string): Name of the application that is connecting to database. Optional. It will be displayed at ``pg_stat_activity``. diff --git a/src/Platforms/PostgreSQLPlatform.php b/src/Platforms/PostgreSQLPlatform.php index a79548501e..70dda0ebaa 100644 --- a/src/Platforms/PostgreSQLPlatform.php +++ b/src/Platforms/PostgreSQLPlatform.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Platforms\Keywords\PostgreSQLKeywords; +use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Index; @@ -249,22 +250,10 @@ public function getAlterTableSQL(TableDiff $diff): array ); } - if ( - $columnDiff->hasTypeChanged() - || $columnDiff->hasPrecisionChanged() - || $columnDiff->hasScaleChanged() - || $columnDiff->hasFixedChanged() - || $columnDiff->hasLengthChanged() - || $columnDiff->hasPlatformOptionsChanged() - ) { - $type = $newColumn->getType(); - - // SERIAL/BIGSERIAL are not "real" types and we can't alter a column to that type - $columnDefinition = $newColumn->toArray(); - $columnDefinition['autoincrement'] = false; - - // here was a server version check before, but DBAL API does not support this anymore. - $query = 'ALTER ' . $newColumnName . ' TYPE ' . $type->getSQLDeclaration($columnDefinition, $this); + $newTypeSQLDeclaration = $this->getTypeSQLDeclaration($newColumn); + $oldTypeSQLDeclaration = $this->getTypeSQLDeclaration($oldColumn); + if ($oldTypeSQLDeclaration !== $newTypeSQLDeclaration) { + $query = 'ALTER ' . $newColumnName . ' TYPE ' . $newTypeSQLDeclaration; $sql[] = 'ALTER TABLE ' . $tableNameSQL . ' ' . $query; } @@ -311,6 +300,17 @@ public function getAlterTableSQL(TableDiff $diff): array ); } + private function getTypeSQLDeclaration(Column $column): string + { + $type = $column->getType(); + + // SERIAL/BIGSERIAL are not "real" types and we can't alter a column to that type + $columnDefinition = $column->toArray(); + $columnDefinition['autoincrement'] = false; + + return $type->getSQLDeclaration($columnDefinition, $this); + } + /** * {@inheritDoc} */ diff --git a/src/Schema/OracleSchemaManager.php b/src/Schema/OracleSchemaManager.php index d965f5fc43..47d87400f1 100644 --- a/src/Schema/OracleSchemaManager.php +++ b/src/Schema/OracleSchemaManager.php @@ -270,7 +270,7 @@ public function createDatabase(string $database): void $params = $this->connection->getParams(); if (isset($params['password'])) { - $statement .= ' IDENTIFIED BY ' . $params['password']; + $statement .= ' IDENTIFIED BY ' . $this->connection->quoteSingleIdentifier($params['password']); } $this->connection->executeStatement($statement); diff --git a/tests/Platforms/PostgreSQLPlatformTest.php b/tests/Platforms/PostgreSQLPlatformTest.php index 109763f8a9..d413f03417 100644 --- a/tests/Platforms/PostgreSQLPlatformTest.php +++ b/tests/Platforms/PostgreSQLPlatformTest.php @@ -805,6 +805,34 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers(): v ); } + public function testTypeChangeWithTheSameSQLGenerationWhileChangingAComment(): void + { + $table1 = Table::editor() + ->setQuotedName('Foo') + ->setColumns(Column::editor() + ->setQuotedName('Bar') + ->setTypeName(Types::DATETIMETZ_MUTABLE) + ->create()) + ->create(); + + $table2 = Table::editor() + ->setQuotedName('Foo') + ->setColumns(Column::editor() + ->setQuotedName('Bar') + ->setTypeName(Types::DATETIMETZ_IMMUTABLE) + ->setComment('Baz') + ->create()) + ->create(); + + $tableDiff = $this->createComparator() + ->compareTables($table1, $table2); + + self::assertSame( + ['COMMENT ON COLUMN "Foo"."Bar" IS \'Baz\''], + $this->platform->getAlterTableSQL($tableDiff), + ); + } + protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(): string { return 'CONSTRAINT "select" UNIQUE (foo)'; diff --git a/tests/TestUtil.php b/tests/TestUtil.php index aea9ed357b..8ba5678781 100644 --- a/tests/TestUtil.php +++ b/tests/TestUtil.php @@ -199,31 +199,12 @@ private static function mapConnectionParameters(array $configuration, string $pr { $parameters = []; - foreach ( - [ - 'driver', - 'user', - 'password', - 'host', - 'dbname', - 'memory', - 'port', - 'server', - 'ssl_key', - 'ssl_cert', - 'ssl_ca', - 'ssl_capath', - 'ssl_cipher', - 'unix_socket', - 'path', - 'charset', - ] as $parameter - ) { - if (! isset($configuration[$prefix . $parameter])) { + foreach ($configuration as $key => $value) { + if (! str_starts_with($key, $prefix)) { continue; } - $parameters[$parameter] = $configuration[$prefix . $parameter]; + $parameters[substr($key, strlen($prefix))] = $value; } if (isset($parameters['port'])) {