DEV: Enable readonly mode for all multisite sites when PG goes down.

DEV: Enable readonly mode for all multisite sites when PG goes down.

The risk here is that the database for one site goes down in the multisite setup and we drop everything to readonly mode. However, I discussed this with Sam and we agree that one database having problem is very rare. Most of the time, it is the entire DB cluster that goes down.

diff --git a/config/initializers/002-rails_failover.rb b/config/initializers/002-rails_failover.rb
index d45a45e..0418654 100644
--- a/config/initializers/002-rails_failover.rb
+++ b/config/initializers/002-rails_failover.rb
@@ -2,12 +2,18 @@
 
 if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
   RailsFailover::ActiveRecord.on_failover do
-    Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
+    RailsMultisite::ConnectionManagement.each_connection do
+      Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
+    end
+
     Sidekiq.pause!("pg_failover") if !Sidekiq.paused?
   end
 
   RailsFailover::ActiveRecord.on_fallback do
-    Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
+    RailsMultisite::ConnectionManagement.each_connection do
+      Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
+    end
+
     Sidekiq.unpause!
   end
 

GitHub sha: ade60b0c