-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
More restore original db config in db rake tasks #51862
base: main
Are you sure you want to change the base?
Conversation
Working on test failures. Next time I'll run more tests before opening a pull. |
end | ||
|
||
def with_stubbed_temporary_connection(&block) | ||
ActiveRecord::Tasks::DatabaseTasks.stub(:with_temporary_connection, ->(*, &block) { block.call }, &block) |
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.
Just passes through with no asserting -- didn't think it was important since the logic doesn't pertain to it.
I did build a version with some asserting (the configs are passed to it) so if that's what we want ... I can swap it out.
I was about to create PR, but this looks closely related what I was looking into (but mysql only). TBH I would move the def create
establish_connection(configuration_hash_without_database)
connection.create_database(db_config.database, creation_options)
establish_connection
end Would become this instead def create
ActiveRecord::Tasks::DatabaseTasks.with_temporary_connection(configuration_hash_without_database) do |conn|
conn.create_database(db_config.database, creation_options)
end
end Same would be for drop and purge. I see PostgreSQL also uses default |
This solves the issue we had when running seeds after setting up other DB that primary, just like in the mentioned issue |
Fixes #51830
Motivation / Background
This is just additional changes that would've been included in #46270
Detail
When running multiple db rake tasks in a single command, we should restore to the original "db config" in between each task.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]