-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: connect to template1 when database is postgres #4321
Conversation
diesel_cli/src/database.rs
Outdated
@@ -429,6 +429,11 @@ fn change_database_of_url( | |||
.last() | |||
.expect("The database url has at least one path segment") | |||
.to_owned(); | |||
|
|||
if database.eq("postgres") { |
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.
I've read the issue and I understand it may be sensible to do this specifically when we are trying to drop a database.
It also sounds likely that at the moment this is the only place at which this function is called.
However the naming of this function fn change_database_of_url(
would not let any future code author expect this behavior, so it's likely to introduce a bug.
=> It looks like it would be best to put this logic where the function is called, that is, in a place where the current code path is about removing the 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.
Thanks for the review! I get what you mean, will push a commit with the required change.
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.
Thanks for fixing this ❤️
Closes #4275.
Description
Diesel explicitly connected to
postgres
to drop any other database, which posed issues whenpostgres
itself was to be dropped.Changes
Added a check for the current database, and connect to
template1
for the case when current database ispostgres
.