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

fix: connect to template1 when database is postgres #4321

Merged
merged 7 commits into from
Nov 11, 2024

Conversation

zaira-bibi
Copy link

Closes #4275.

Description
Diesel explicitly connected to postgres to drop any other database, which posed issues when postgres itself was to be dropped.

Changes
Added a check for the current database, and connect to template1 for the case when current database is postgres.

@weiznich weiznich requested a review from a team October 24, 2024 10:38
@@ -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") {
Copy link
Member

@Ten0 Ten0 Oct 24, 2024

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.

Copy link
Author

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.

Copy link
Member

@weiznich weiznich left a 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 ❤️

@weiznich weiznich added this pull request to the merge queue Nov 11, 2024
Merged via the queue into diesel-rs:master with commit a459c31 Nov 11, 2024
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

diesel database reset errors with Failed to execute a database query
3 participants