-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Tie default DB name to database user name #1660
Conversation
de7fb60
to
6063d7e
Compare
The previous behaviour was at variance with the native client behaviour, per: https://www.postgresql.org/docs/10/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS > The database name. Defaults to be the same as the user name. > In certain contexts, the value is checked for extended formats...
I am really not sure about the test
The motivation for this patch, is that we have some It seems like something changed here, perhaps in the way Knex uses |
Note that this is a breaking change for anything setting or relying on |
@@ -50,8 +54,11 @@ var ConnectionParameters = function (config) { | |||
config = Object.assign({}, config, parse(config.connectionString)) | |||
} | |||
|
|||
var dbDefaulting = function () { return this.user || defaults['database'] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for this.user
to be falsy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the implementation, it's set with val('user', config)
which can be false when (a) there is no default set and (b) the corresponding environment variable is not set.
From the outside, URLs like postgres:///
don't have a user, so it stands to reason the implementation has to allow it to be falsey.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default has to be set to something; if it’s undefined
, the connection is going to fail anyway. I think this can just be const getDefaultDatabase = () => this.user
. (At that point, it doesn’t even need to be a function – this.user
can be passed in directly.)
Perhaps there is some intermediate possible? The current behavior is such that |
A breaking change just means it needs a major version increment. |
Maybe if we allowed
|
I will merge this as soon as I cut the next major version. Sorry for the delay. |
Actually looks like 1679 supersedes this, so closing in favor of that one. |
The previous behaviour was at variance with the native client behaviour, per:
https://www.postgresql.org/docs/10/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS