Update retrieving database config hash for Rails >= 6.1#70
Update retrieving database config hash for Rails >= 6.1#70JuanitoFatas wants to merge 4 commits intoamatsuda:masterfrom
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
| 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.
@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.
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 <takkanm@gmail.com>
| 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.
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.
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!