Skip to content

Commit 68b8b41

Browse files
committed
Fixes #5 Don't install when primary database is not available
1 parent 013e997 commit 68b8b41

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/active_record_replica/active_record_replica.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ def self.install!(adapter_class = nil, environment = nil)
1818
return
1919
end
2020

21+
# When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised
22+
active_db_connection = ActiveRecord::Base.connection.active? rescue false
23+
unless active_db_connection
24+
ActiveRecord::Base.logger.info("ActiveRecord not connected so not installing ActiveRecordReplica")
25+
return
26+
end
27+
2128
version = ActiveRecordReplica::VERSION
2229
ActiveRecord::Base.logger.info("ActiveRecordReplica.install! v#{version} Establishing connection to replica database")
2330
Replica.establish_connection(replica_config)

0 commit comments

Comments
 (0)