Skip to content

Commit 3fb5745

Browse files
authored
Merge pull request #5705 from morozov/deprecate-pdo-pgsql-default-dbname
Deprecate PostgreSQL-specific connection parameters and behavior
2 parents d5da8b4 + 982a91d commit 3fb5745

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

UPGRADE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ awareness about deprecated code.
88

99
# Upgrade to 3.5
1010

11+
## Deprecated default PostgreSQL connection database.
12+
13+
Relying on the DBAL connecting to the "postgres" database by default is deprecated. Unless you want to have the server
14+
determine the default database for the connection, specify the database name explicitly.
15+
16+
## Deprecated the "default_dbname" parameter of the wrapper `Connection`.
17+
18+
The "default_dbname" parameter of the wrapper `Connection` has been deprecated. Use "dbname" instead.
19+
1120
## Deprecated the "platform" parameter of the wrapper `Connection`.
1221

1322
The "platform" parameter of the wrapper `Connection` has been deprecated. Use a driver middleware that would instantiate

docs/en/reference/configuration.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ pdo_pgsql
203203
- ``dbname`` (string): Name of the database/schema to connect to.
204204
- ``charset`` (string): The charset used when connecting to the
205205
database.
206-
- ``default_dbname`` (string): Override the default database (postgres)
207-
to connect to.
208206
- ``sslmode`` (string): Determines whether or with what priority
209207
a SSL TCP/IP connection will be negotiated with the server.
210208
See the list of available modes:

src/Driver/PDO/PgSQL/Driver.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
66
use Doctrine\DBAL\Driver\PDO\Connection;
77
use Doctrine\DBAL\Driver\PDO\Exception;
8+
use Doctrine\Deprecations\Deprecation;
89
use PDO;
910
use PDOException;
1011

@@ -73,11 +74,25 @@ private function constructPdoDsn(array $params): string
7374
if (isset($params['dbname'])) {
7475
$dsn .= 'dbname=' . $params['dbname'] . ';';
7576
} elseif (isset($params['default_dbname'])) {
77+
Deprecation::trigger(
78+
'doctrine/dbal',
79+
'https://github.com/doctrine/dbal/pull/5705',
80+
'The "default_dbname" connection parameter is deprecated. Use "dbname" instead.',
81+
);
82+
7683
$dsn .= 'dbname=' . $params['default_dbname'] . ';';
7784
} else {
85+
if (isset($params['user']) && $params['user'] !== 'postgres') {
86+
Deprecation::trigger(
87+
'doctrine/dbal',
88+
'https://github.com/doctrine/dbal/pull/5705',
89+
'Relying on the DBAL connecting to the "postgres" database by default is deprecated.'
90+
. ' Unless you want to have the server determine the default database for the connection,'
91+
. ' specify the database name explicitly.',
92+
);
93+
}
94+
7895
// Used for temporary connections to allow operations like dropping the database currently connected to.
79-
// Connecting without an explicit database does not work, therefore "postgres" database is used
80-
// as it is mostly present in every server setup.
8196
$dsn .= 'dbname=postgres;';
8297
}
8398

0 commit comments

Comments
 (0)