Use custom class for pending migrations connection #49701
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In bensheldon/good_job#1103 it was reported that a connection not established is being seen when there are multiple configs for an environment (a multi-db app).
While I think that something is happening where Good Job is accessing the connection while we're checking for pending migrations, this could happen in other gems if we're clobbering the connection on
ActiveRecord::Base
that is needed.Here we are making a special class to establish connections to the database. Because the class does not inherit from
Base
and establishes it's own connection, it won't clobber any existing connections onBase
, leaving them in-tact while the app boots.The reason this wasn't seen in 7.0 is because pending migrations didn't check all the available configs. Once that was fixed this error appeared.
I didn't add a test for this because it's really hard to reproduce without good job and actually booting a server and running a request.
Fixes: #49689