-
Notifications
You must be signed in to change notification settings - Fork 93
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
Update retrieving database config hash for Rails >= 6.1 #70
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bc05f64
Update retrieving database config hash for Rails >= 6.1
JuanitoFatas 59868b4
The database key is a symbol from configs_for
JuanitoFatas ca4d62b
Available since Rails 6.0.0
JuanitoFatas c376261
Pull db config from connection name for Rails < 6
JuanitoFatas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ def database_configuration | |
end | ||
|
||
def create_cleaner(connection_name) | ||
config = database_configuration[connection_name] or raise %Q[Database configuration named "#{connection_name}" is not configured.] | ||
config = get_config_from(connection_name) or raise %Q[Database configuration named "#{connection_name}" is not configured.] | ||
|
||
Cleaner.new(config: config, connection_name: connection_name, only: @only, except: @except).tap {|c| @cleaners << c} | ||
end | ||
|
@@ -82,16 +82,28 @@ def all_table_names(connection) | |
end | ||
end | ||
|
||
def get_config_from(connection_name) | ||
if Gem::Version.new(Rails.version) >= Gem::Version.new("6.0.0") | ||
database_configuration.configs_for(env_name: connection_name).first.configuration_hash | ||
else | ||
database_configuration[connection_name] | ||
end | ||
end | ||
|
||
def get_cache_key(connection_pool) | ||
if connection_pool.respond_to?(:db_config) # ActiveRecord >= 6.1 | ||
connection_pool.db_config.config | ||
if Gem::Version.new(Rails.version) >= Gem::Version.new("6.0.0") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this check? The line above already checks for ActiveRecord >= 6.1. In any case, |
||
connection_pool.db_config.configuration_hash | ||
else | ||
connection_pool.db_config.config | ||
end | ||
else | ||
connection_pool.spec.config | ||
end | ||
end | ||
end | ||
|
||
private_class_method :get_cache_key | ||
private_class_method :get_config_from, :get_cache_key | ||
end | ||
|
||
begin | ||
|
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
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.
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.
configs_for
is available on Rails 6.0 butconfiguration_hash
is only available on Rails 6.1. This causes the error on the build.