DEV: Allow multisite apps to boot with reading connection handler.

DEV: Allow multisite apps to boot with reading connection handler.

diff --git a/Gemfile.lock b/Gemfile.lock
index 189cfed..2870d86 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -288,7 +288,7 @@ GEM
       nokogiri (>= 1.6)
     rails-html-sanitizer (1.3.0)
       loofah (~> 2.3)
-    rails_multisite (2.2.2)
+    rails_multisite (2.3.0)
       activerecord (> 5.0, < 7)
       railties (> 5.0, < 7)
     railties (6.0.3.1)
diff --git a/config/initializers/002-rails_failover.rb b/config/initializers/002-rails_failover.rb
index d53451b..54692b7 100644
--- a/config/initializers/002-rails_failover.rb
+++ b/config/initializers/002-rails_failover.rb
@@ -17,6 +17,13 @@ if ENV["REDIS_RAILS_FAILOVER"]
 end
 
 if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
+  if Rails.configuration.multisite
+    if ActiveRecord::Base.current_role == ActiveRecord::Base.reading_role
+      RailsMultisite::ConnectionManagement.default_connection_handler =
+        ActiveRecord::Base.connection_handlers[ActiveRecord::Base.reading_role]
+    end
+  end
+
   RailsFailover::ActiveRecord.on_failover do
     RailsMultisite::ConnectionManagement.each_connection do
       Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
@@ -29,6 +36,11 @@ if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
       Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
       Sidekiq.unpause! if Sidekiq.paused?
     end
+
+    if Rails.configuration.multisite
+      RailsMultisite::ConnectionManagement.default_connection_handler =
+        ActiveRecord::Base.connection_handlers[ActiveRecord::Base.writing_role]
+    end
   end
 
   module Discourse

GitHub sha: 2ce829cc