Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -283,6 +284,7 @@ pdo_pgsql / pgsql
See `www.postgresql.org/docs/9.4/static/libpq-connect.html#LIBPQ-CONNECT-SSLCRL <https://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 <https://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``.

Expand Down
32 changes: 16 additions & 16 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/OracleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions tests/Platforms/PostgreSQLPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
Expand Down
25 changes: 3 additions & 22 deletions tests/TestUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
Loading