forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move calls on Base connection to methods for rake tasks
This PR aims to contain calls to `Base.connection` and `Base.establish_connection` in active record rake tasks and the migration code. In a follow up PR I will swap out the `Base` class for a temporary class which will allow us to stop clobbering `Base` in the active record rails tasks. This work is an important step to achieve moving away from Active Record's dependence on `Base.connection` and `Base.establish_connection`. The reliance on `Base.connection` is problematic for sharding support and calling `Base.establish_connection` in the Rake tasks (without any warning message) indicates it's ok for applications to do the same (outside these tasks, it's not). I've vetted the approach of swapping out `Base` for a temporary class in another branch but decided that it would be easier to demonstrate and contain the changes if I first contained these calls. The major changes in this PR are: * Contain `Base.connection` in `Tasks.migration_connection` and replace calls to each * Contain `Base.establish_connection` in `Tasks.establish_connection` and replace calls to each * Add a `with_temporary_connection_for_each` method for cases where we need to loop over each config and set the connection back afterwards * Add a `with_temporary_connection(db_config)` method for cases where we have one config but need to establish a new connection and set the old one back. * Update every place we were looping through configs to establish a connection with the new temporary connection methods. There are a lot of changes here but I've pulled out everything that didn't need to be in this commit into other PRs. Once this is merged, I'll create the next PR that replaces `Base` the new methods in `Tasks` with a temporary connection and then we will officially be no longer clobbering `Base` in these tasks. This also reduces complexity because we won't need to ensure we set `Base.connection` back at the end. Once that is working and all internal methods are using the new temp class I'll deprecate calls on `Base.connection` in these methods. Most applications just override the task but not the actual methods in `Tasks` so my hope is this will be smooth-ish. However, nothing will stop applications from still using `Base.connection` for a very long time if they still want to clobber.
- Loading branch information
1 parent
a02c235
commit 901828f
Showing
4 changed files
with
215 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.