From f3f0123f880b132294da8e1083364d052e692814 Mon Sep 17 00:00:00 2001
From: Mike Carlton <mike.carlton@illumio.com>
Date: Tue, 25 May 2021 10:02:49 -0700
Subject: [PATCH 1/2] Update for rails 6

---
 lib/querrel/connection_resolver.rb | 27 ++++++++++++++-------------
 lib/querrel/querreller.rb          | 14 +-------------
 lib/querrel/version.rb             |  2 +-
 querrel.gemspec                    |  4 ++--
 test/instance_test.rb              |  4 ++--
 test/non_instance_test.rb          |  4 ++--
 test/setup/active_record_config.rb | 12 +++++++-----
 7 files changed, 29 insertions(+), 38 deletions(-)

diff --git a/lib/querrel/connection_resolver.rb b/lib/querrel/connection_resolver.rb
index 489fcfc..41acd11 100644
--- a/lib/querrel/connection_resolver.rb
+++ b/lib/querrel/connection_resolver.rb
@@ -1,32 +1,33 @@
 module Querrel
   class ConnectionResolver
-    attr_accessor :resolver
 
     def initialize(conns, db_names)
       if db_names
-        base_spec = ActiveRecord::Base.connection_config
+        base_spec = ActiveRecord::Base.connection_db_config.configuration_hash
 
         specs = conns.map do |c|
-          [c, base_spec.dup.update(database: c)]
+          [ c.to_s, base_spec.dup.update(database: c) ]
         end
-        specs = Hash[specs]
+        @specs = Hash[specs]
       else
         case conns
         when Hash
-          specs = conns
+          @specs = conns
         when Array
-          conns.map!(&:to_s)
-          specs = ActiveRecord::Base.configurations.select{ |n, _| conns.include?(n.to_s) }
+          specs = conns.map do |c|
+            [ c.to_s, ActiveRecord::Base.configurations.find_db_config(c).configuration_hash ]
+          end
+          @specs = Hash[specs]
         end
       end
+    end
 
-      @resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(specs)
+    def resolve(db)
+      @specs[db.to_s]
     end
 
-    [:configurations, :spec, :resolve].each do |m|
-      define_method(m) do |*args, &block|
-        @resolver.send(m, *args, &block)
-      end
+    def configurations
+      @specs
     end
   end
-end
\ No newline at end of file
+end
diff --git a/lib/querrel/querreller.rb b/lib/querrel/querreller.rb
index 3325260..f8fa4b6 100644
--- a/lib/querrel/querreller.rb
+++ b/lib/querrel/querreller.rb
@@ -38,20 +38,8 @@ def run(options = {}, &blk)
       pool.do_your_thang!
     end
 
-    def retrieve_connection_spec(db, resolver)
-      resolver.spec(db.to_sym)
-    end
-
     def retrieve_connection_config(db, resolver)
       resolver.resolve(db.to_sym)
     end
-
-    def while_connected_to(db, resolver, &b)
-      conf = resolver.spec(db.to_sym)
-      pool = ActiveRecord::ConnectionAdapters::ConnectionPool.new(conf)
-      pool.with_connection(&b)
-    ensure
-      pool.disconnect!
-    end
   end
-end
\ No newline at end of file
+end
diff --git a/lib/querrel/version.rb b/lib/querrel/version.rb
index a41059f..c935ba8 100644
--- a/lib/querrel/version.rb
+++ b/lib/querrel/version.rb
@@ -1,3 +1,3 @@
 module Querrel
-  VERSION = "1.4.0"
+  VERSION = "2.0.0"
 end
diff --git a/querrel.gemspec b/querrel.gemspec
index 0b93e6e..905977a 100644
--- a/querrel.gemspec
+++ b/querrel.gemspec
@@ -17,9 +17,9 @@ Gem::Specification.new do |spec|
   spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
   spec.require_paths = ["lib"]
 
-  spec.add_runtime_dependency "activerecord", ">= 4.0"
+  spec.add_runtime_dependency "activerecord", "~> 6.0"
 
-  spec.add_development_dependency "bundler", "~> 1.6"
+  spec.add_development_dependency "bundler", ">= 2.0"
   spec.add_development_dependency "rake"
   spec.add_development_dependency "sqlite3", "~> 1.3.5"
   spec.add_development_dependency "database_rewinder", "~> 0"
diff --git a/test/instance_test.rb b/test/instance_test.rb
index 46037e9..86e6826 100644
--- a/test/instance_test.rb
+++ b/test/instance_test.rb
@@ -48,7 +48,7 @@ def test_runner
 
     @q.run do
       s.synchronize do
-        configs_actual << Product.connection_config
+        configs_actual << Product.connection_db_config.configuration_hash
       end
     end
 
@@ -59,4 +59,4 @@ def test_runner
 
     assert_equal configs, configs_actual
   end
-end
\ No newline at end of file
+end
diff --git a/test/non_instance_test.rb b/test/non_instance_test.rb
index c837530..2996f0b 100644
--- a/test/non_instance_test.rb
+++ b/test/non_instance_test.rb
@@ -48,7 +48,7 @@ def test_runner
     configs_actual = []
     Querrel.run(on: @dbs) do
       s.synchronize do
-        configs_actual << Product.connection_config
+        configs_actual << Product.connection_db_config.configuration_hash
       end
     end
 
@@ -59,4 +59,4 @@ def test_runner
 
     assert_equal configs, configs_actual
   end
-end
\ No newline at end of file
+end
diff --git a/test/setup/active_record_config.rb b/test/setup/active_record_config.rb
index 06e0549..99c3ab8 100644
--- a/test/setup/active_record_config.rb
+++ b/test/setup/active_record_config.rb
@@ -9,8 +9,8 @@
 ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
 
 # load schema and fixtures to each db
-ActiveRecord::Base.configurations.keys.each do |c|
-  ActiveRecord::Base.establish_connection(c.to_sym)
+ActiveRecord::Base.configurations.configurations.each do |config|
+  ActiveRecord::Base.establish_connection(config)
   ActiveRecord::Migration.suppress_messages do
     load('schema.rb')
   end
@@ -21,8 +21,10 @@
 
 require "active_support"
 require "database_rewinder"
+require "database_rewinder/cleaner"
 
 # configure DatabaseRewinder
-ActiveRecord::Base.configurations.keys.each do |c|
-  DatabaseRewinder[c]
-end
\ No newline at end of file
+DatabaseRewinder.init
+ActiveRecord::Base.configurations.configurations.each do |config|
+  DatabaseRewinder[config.env_name]
+end

From cdef7292c23c7e95678e814430056c0d28e8bb36 Mon Sep 17 00:00:00 2001
From: Mike Carlton <mike.carlton@illumio.com>
Date: Tue, 25 May 2021 11:38:37 -0700
Subject: [PATCH 2/2] Update README for rails 6

---
 README.md | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index e081b11..5f9fb27 100644
--- a/README.md
+++ b/README.md
@@ -4,9 +4,15 @@ Querrel makes it easy to query multiple databases in parallel (threads) using Ac
 
 ## Installation
 
+Querrel version >= 2.0 is required for Rails 6 (and does not support earlier versions).  For Rails versions 5.x and earlier, use version 1.4.
+
 Add this line to your application's Gemfile:
 
-    gem 'querrel'
+    gem 'querrel', '~> 2.0'		# Rails 6
+    
+or
+
+    gem 'querrel', '~> 1.4'		# Rails 5 and earlier
 
 And then execute: