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

Deprecate PostgreSQL-specific connection parameters and behavior #5705

Merged
merged 2 commits into from
Oct 1, 2022

Conversation

morozov
Copy link
Member

@morozov morozov commented Sep 29, 2022

The default_dbname parameter was introduced in #2284 as a hack that was supposed to address doctrine/DoctrineBundle#402.

My understanding of the hack is that it would force the connection to return the database currently connected to instead of the database specified in the configuration:

return (isset($params['dbname']))
? $params['dbname']
: $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn();

This hack is irrelevant as of #3606. Since 3.0.0, the connection will always return the name of the database currently connected to. Therefore, this parameter is no longer necessary.


The reason to hardcode postgres as the default database doesn't seem valid:

// Connecting without an explicit database does not work, therefore "postgres" database is used

According to this article,

The default name of the database is the same as that of the user.

This could be reproduced with the following script:

<?php

$conn = new PDO('pgsql:host=localhost;port=5432;user=postgres;password=Passw0rd');

if (!$conn) {
    exit(1);
}

echo $conn->query('SELECT CURRENT_DATABASE()')
    ->fetch(PDO::FETCH_COLUMN), PHP_EOL;
// postgres

In any event, it is not the job of the DBAL to provide such defaults. If the user is not happy with the defaults provided by the driver, they should provide the database name explicitly.

@morozov morozov added this to the 3.5.0 milestone Sep 29, 2022
@morozov morozov marked this pull request as ready for review September 30, 2022 00:10
derrabus
derrabus previously approved these changes Sep 30, 2022
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5705',
'The "default_dbname" connection parameter is deprecated. Use "dbname" instead.',
__METHOD__,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter appears to be unused

'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.',
__METHOD__,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@morozov morozov force-pushed the deprecate-pdo-pgsql-default-dbname branch from aecb585 to 982a91d Compare September 30, 2022 14:54
@morozov morozov requested a review from greg0ire October 1, 2022 15:51
@morozov morozov merged commit 3fb5745 into doctrine:3.5.x Oct 1, 2022
@morozov morozov deleted the deprecate-pdo-pgsql-default-dbname branch October 1, 2022 16:01
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants