From 80423c8f016c1512a910f542a341b9416130cf4b Mon Sep 17 00:00:00 2001 From: Alex Ghiculescu Date: Tue, 2 Feb 2021 15:21:44 -0700 Subject: [PATCH] Fix deprecation warning on Rails 6.1 --- .../active_record/devise_generator.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/generators/active_record/devise_generator.rb b/lib/generators/active_record/devise_generator.rb index 7319c47f..2198310d 100644 --- a/lib/generators/active_record/devise_generator.rb +++ b/lib/generators/active_record/devise_generator.rb @@ -86,9 +86,24 @@ RUBY Rails::VERSION::MAJOR >= 5 end + def rails61_and_up? + Rails::VERSION::MAJOR > 6 || (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR >= 1) + end + def postgresql? - config = ActiveRecord::Base.configurations[Rails.env] - config && config['adapter'] == 'postgresql' + ar_config && ar_config['adapter'] == 'postgresql' + end + + def ar_config + if ActiveRecord::Base.configurations.respond_to?(:configs_for) + if rails61_and_up? + ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: "primary").configuration_hash + else + ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: "primary").config + end + else + ActiveRecord::Base.configurations[Rails.env] + end end def migration_version