Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PostgreSQL-specific connection parameters and behavior #5711

Merged
merged 2 commits into from
Oct 3, 2022
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
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ awareness about deprecated code.

# Upgrade to 4.0

## BC BREAK: removed default PostgreSQL connection database.

When connecting to a PostgreSQL server, the driver will no longer connect to the "postgres" database by default.

## BC BREAK: removed support for the "default_dbname" parameter of the wrapper `Connection`.

The "default_dbname" parameter of the wrapper `Connection` is no longer supported.

## BC BREAK: removed fallback connection used to determine the database platform.

When determining the database platform, if an attempt to connect using the provided configuration fails,
Expand Down
22 changes: 0 additions & 22 deletions src/Driver/PDO/PgSQL/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
use Doctrine\DBAL\Driver\PDO\Connection;
use Doctrine\DBAL\Driver\PDO\Exception;
use Doctrine\Deprecations\Deprecation;
use PDO;
use PDOException;

Expand Down Expand Up @@ -73,27 +72,6 @@ private function constructPdoDsn(array $params): string

if (isset($params['dbname'])) {
$dsn .= 'dbname=' . $params['dbname'] . ';';
} elseif (isset($params['default_dbname'])) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5705',
'The "default_dbname" connection parameter is deprecated. Use "dbname" instead.',
);

$dsn .= 'dbname=' . $params['default_dbname'] . ';';
} else {
if (isset($params['user']) && $params['user'] !== 'postgres') {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5705',
'Relying on the DBAL connecting to the "postgres" database by default is deprecated.'
. ' Unless you want to have the server determine the default database for the connection,'
. ' specify the database name explicitly.',
);
}

// Used for temporary connections to allow operations like dropping the database currently connected to.
$dsn .= 'dbname=postgres;';
}

if (isset($params['sslmode'])) {
Expand Down
3 changes: 0 additions & 3 deletions src/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* @psalm-type OverrideParams = array{
* charset?: string,
* dbname?: string,
* default_dbname?: string,
* driver?: key-of<self::DRIVER_MAP>,
* driverClass?: class-string<Driver>,
* driverOptions?: array<mixed>,
Expand All @@ -51,7 +50,6 @@
* charset?: string,
* dbname?: string,
* defaultTableOptions?: array<string, mixed>,
* default_dbname?: string,
* driver?: key-of<self::DRIVER_MAP>,
* driverClass?: class-string<Driver>,
* driverOptions?: array<mixed>,
Expand Down Expand Up @@ -137,7 +135,6 @@ private function __construct()
* @psalm-param array{
* charset?: string,
* dbname?: string,
* default_dbname?: string,
* driver?: key-of<self::DRIVER_MAP>,
* driverClass?: class-string<Driver>,
* driverOptions?: array<mixed>,
Expand Down
48 changes: 0 additions & 48 deletions tests/Functional/Driver/PDO/PgSQL/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\DBAL\Tests\Functional\Driver\PDO\PgSQL;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\PDO\PgSQL\Driver;
use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest;
Expand All @@ -28,53 +27,6 @@ protected function setUp(): void
self::markTestSkipped('This test requires the pdo_pgsql driver.');
}

/** @dataProvider getDatabaseParameter */
public function testDatabaseParameters(
?string $databaseName,
?string $defaultDatabaseName,
?string $expectedDatabaseName,
): void {
$params = $this->connection->getParams();

if ($databaseName !== null) {
$params['dbname'] = $databaseName;
} else {
unset($params['dbname']);
}

if ($defaultDatabaseName !== null) {
$params['default_dbname'] = $defaultDatabaseName;
}

$connection = new Connection(
$params,
$this->connection->getDriver(),
$this->connection->getConfiguration(),
$this->connection->getEventManager(),
);

self::assertSame(
$expectedDatabaseName,
$connection->getDatabase(),
);
}

/** @return mixed[][] */
public static function getDatabaseParameter(): iterable
{
$params = TestUtil::getConnectionParams();
$realDatabaseName = $params['dbname'] ?? '';
$dummyDatabaseName = $realDatabaseName . 'a';

return [
// dbname, default_dbname, expected
[$realDatabaseName, null, $realDatabaseName],
[$realDatabaseName, $dummyDatabaseName, $realDatabaseName],
[null, $realDatabaseName, $realDatabaseName],
[null, null, static::getDatabaseNameForConnectionWithoutDatabaseNameParameter()],
];
}

public function testConnectsWithApplicationNameParameter(): void
{
$parameters = $this->connection->getParams();
Expand Down