From f472a6154e84d41e94c0fe68b82df7198247b863 Mon Sep 17 00:00:00 2001 From: rubic0n Date: Sat, 13 Feb 2021 22:59:02 -0600 Subject: [PATCH] Mark the replicas as replicas Rails won't even attempt to write to a replica. Without this option, a write attempt would actually run against Postgres, and it would be up to Postgres to throw a readonly error. Additionally, marking it as a replica teaches ActiveRecord that it should not attempt to run migrations against this connection. https://api.rubyonrails.org/classes/ActiveRecord/DatabaseConfigurations.html#method-i-configs_for I'm actually pretty sure that the lack of `replica: true` is why there's currently a db/slave1_schema.rb and db/slave2_schema.rb --- config/database.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/database.yml b/config/database.yml index e60018bd..03878e8d 100644 --- a/config/database.yml +++ b/config/database.yml @@ -13,9 +13,11 @@ development: slave1: <<: *default url: <%= ENV['DB_SLAVE1_URL'] %> + replica: true slave2: <<: *default url: <%= ENV['DB_SLAVE2_URL'] %> + replica: true # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". @@ -43,6 +45,8 @@ production: slave1: <<: *default url: <%= ENV['DB_SLAVE1_URL'] %> + replica: true slave2: <<: *default url: <%= ENV['DB_SLAVE1_URL'] %> + replica: true