-
Notifications
You must be signed in to change notification settings - Fork 92
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
Conversation
Rails 6.1 changed the way to retrieve the database config hash to DatabaseConfigurations#configs_for(env_name: "test").configuration_hash The old way will stop working in Rails 6.2. DEPRECATION WARNING: [] is deprecated and will be removed from Rails 6.2 (Use configs_for) (called from create_cleaner at lib/database_rewinder.rb:19) DEPRECATION WARNING: DatabaseConfig#config will be removed in 6.2.0 in favor of DatabaseConfigurations#configuration_hash which returns a hash with symbol keys (called from get_cache_key at lib/database_rewinder.rb:87)
lib/database_rewinder.rb
Outdated
@@ -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.1.0.alpha") |
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.
@eileencodes Should we check configs_for
change for Rails 6.0 or 6.1? I found the refactoring introduced in rails/rails#32274 which says v6.0.0.beta1
.
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
has been available since 6.0. The hash implementation will be removed in 6.2.
`ActiveRecord::Base.configurations` in edge rails returns Symbol key. And I watched the following discussion. amatsuda#70 (comment) I was referring to this comment as well.
Co-authored-by: Mitsutaka Mimura <[email protected]>
if Gem::Version.new(Rails.version) >= Gem::Version.new("6.0.0") | ||
database_configuration.configs_for(env_name: connection_name).first.configuration_hash |
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 but configuration_hash
is only available on Rails 6.1. This causes the error on the build.
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 comment
The 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, configuration_hash
is only available on Rails 6.1.
@JuanitoFatas How's it going this pull request? |
Somehow I missed this one in #67. Changed the way to retrieve the database config hash because the old way will stop working in Rails 6.2.
This PR fixes following warnings:
@eileencodes Does this look good to you? Thanks!