From f431acb36a8b0551124f0ff1f3f7d3c8ba1b14c6 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 1 Oct 2022 13:04:08 -0700 Subject: [PATCH 1/2] Remove default PostgreSQL connection database --- UPGRADE.md | 4 ++++ src/Driver/PDO/PgSQL/Driver.php | 13 ------------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 390bfc651de..2e4545cc626 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,10 @@ awareness about deprecated code. # Upgrade to 4.0 +## 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, diff --git a/src/Driver/PDO/PgSQL/Driver.php b/src/Driver/PDO/PgSQL/Driver.php index 538318b8395..eef074503a4 100644 --- a/src/Driver/PDO/PgSQL/Driver.php +++ b/src/Driver/PDO/PgSQL/Driver.php @@ -81,19 +81,6 @@ private function constructPdoDsn(array $params): string ); $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'])) { From 3aa0d3e40760843f0b2ee52dca857c29dc30a411 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 26 Sep 2021 13:08:54 -0700 Subject: [PATCH 2/2] Remove default_dbname parameter of wrapper Connection --- UPGRADE.md | 4 ++ src/Driver/PDO/PgSQL/Driver.php | 9 ---- src/DriverManager.php | 3 -- .../Driver/PDO/PgSQL/DriverTest.php | 48 ------------------- 4 files changed, 4 insertions(+), 60 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 2e4545cc626..13d8a1df9df 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,10 @@ 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. diff --git a/src/Driver/PDO/PgSQL/Driver.php b/src/Driver/PDO/PgSQL/Driver.php index eef074503a4..811ef51866a 100644 --- a/src/Driver/PDO/PgSQL/Driver.php +++ b/src/Driver/PDO/PgSQL/Driver.php @@ -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; @@ -73,14 +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'] . ';'; } 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();