Skip to content

Commit

Permalink
Deprecate default PostgreSQL connection database
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Sep 30, 2022
1 parent e7f7f28 commit 982a91d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ awareness about deprecated code.

# Upgrade to 3.5

## Deprecated default PostgreSQL connection database.

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.

## Deprecated the "default_dbname" parameter of the wrapper `Connection`.

The "default_dbname" parameter of the wrapper `Connection` has been deprecated. Use "dbname" instead.
Expand Down
12 changes: 10 additions & 2 deletions src/Driver/PDO/PgSQL/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,17 @@ 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.
// 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;';
}

Expand Down

0 comments on commit 982a91d

Please sign in to comment.