From 8c2d52efa69447b9f91186dd0e3d1122101714eb Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 26 Sep 2021 13:08:54 -0700 Subject: [PATCH] Remove redundant dbname=postgres PostgreSQL DSN See: https://github.com/doctrine/DoctrineBundle/issues/402 See: https://github.com/doctrine/dbal/pull/3606 --- docs/en/reference/configuration.rst | 2 - src/Driver/PDO/PgSQL/Driver.php | 7 --- src/DriverManager.php | 3 -- .../Driver/PDO/PgSQL/DriverTest.php | 48 ------------------- 4 files changed, 60 deletions(-) diff --git a/docs/en/reference/configuration.rst b/docs/en/reference/configuration.rst index 164b9f61bec..e8ac39b8af3 100644 --- a/docs/en/reference/configuration.rst +++ b/docs/en/reference/configuration.rst @@ -203,8 +203,6 @@ pdo_pgsql - ``dbname`` (string): Name of the database/schema to connect to. - ``charset`` (string): The charset used when connecting to the database. -- ``default_dbname`` (string): Override the default database (postgres) - to connect to. - ``sslmode`` (string): Determines whether or with what priority a SSL TCP/IP connection will be negotiated with the server. See the list of available modes: diff --git a/src/Driver/PDO/PgSQL/Driver.php b/src/Driver/PDO/PgSQL/Driver.php index a83c4211ecd..811ef51866a 100644 --- a/src/Driver/PDO/PgSQL/Driver.php +++ b/src/Driver/PDO/PgSQL/Driver.php @@ -72,13 +72,6 @@ private function constructPdoDsn(array $params): string if (isset($params['dbname'])) { $dsn .= 'dbname=' . $params['dbname'] . ';'; - } elseif (isset($params['default_dbname'])) { - $dsn .= 'dbname=' . $params['default_dbname'] . ';'; - } else { - // Used for temporary connections to allow operations like dropping the database currently connected to. - // Connecting without an explicit database does not work, therefore "postgres" database is used - // as it is mostly present in every server setup. - $dsn .= 'dbname=postgres;'; } if (isset($params['sslmode'])) { diff --git a/src/DriverManager.php b/src/DriverManager.php index e929b582408..665846c81a4 100644 --- a/src/DriverManager.php +++ b/src/DriverManager.php @@ -35,7 +35,6 @@ * @psalm-type OverrideParams = array{ * charset?: string, * dbname?: string, - * default_dbname?: string, * driver?: key-of, * driverClass?: class-string, * driverOptions?: array, @@ -51,7 +50,6 @@ * charset?: string, * dbname?: string, * defaultTableOptions?: array, - * default_dbname?: string, * driver?: key-of, * driverClass?: class-string, * driverOptions?: array, @@ -137,7 +135,6 @@ private function __construct() * @psalm-param array{ * charset?: string, * dbname?: string, - * default_dbname?: string, * driver?: key-of, * driverClass?: class-string, * driverOptions?: array, diff --git a/tests/Functional/Driver/PDO/PgSQL/DriverTest.php b/tests/Functional/Driver/PDO/PgSQL/DriverTest.php index cbfcd3a4f8b..a6b85f59a0b 100644 --- a/tests/Functional/Driver/PDO/PgSQL/DriverTest.php +++ b/tests/Functional/Driver/PDO/PgSQL/DriverTest.php @@ -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; @@ -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();