Skip to content

Commit 013e997

Browse files
committed
Fixes #10
Use ActiveRecord::Base.configurations so that Active Record Replica can be disabled when the relevant database has not yet been created,
1 parent 85c831f commit 013e997

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

lib/active_record_replica/active_record_replica.rb

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@ module ActiveRecordReplica
1212
# In a non-Rails environment, supply the environment such as
1313
# 'development', 'production'
1414
def self.install!(adapter_class = nil, environment = nil)
15-
replica_config =
16-
if ActiveRecord::Base.connection.respond_to?(:config)
17-
ActiveRecord::Base.connection.config[:replica]
18-
else
19-
ActiveRecord::Base.configurations[environment || Rails.env]['replica']
20-
end
21-
if replica_config
22-
ActiveRecord::Base.logger.info "ActiveRecordReplica.install! v#{ActiveRecordReplica::VERSION} Establishing connection to replica database"
23-
Replica.establish_connection(replica_config)
24-
25-
# Inject a new #select method into the ActiveRecord Database adapter
26-
base = adapter_class || ActiveRecord::Base.connection.class
27-
base.include(Extensions)
28-
else
29-
ActiveRecord::Base.logger.info "ActiveRecordReplica not installed since no replica database defined"
15+
replica_config = ActiveRecord::Base.configurations[environment || Rails.env]["replica"]
16+
unless replica_config
17+
ActiveRecord::Base.logger.info("ActiveRecordReplica not installed since no replica database defined")
18+
return
3019
end
20+
21+
version = ActiveRecordReplica::VERSION
22+
ActiveRecord::Base.logger.info("ActiveRecordReplica.install! v#{version} Establishing connection to replica database")
23+
Replica.establish_connection(replica_config)
24+
25+
# Inject a new #select method into the ActiveRecord Database adapter
26+
base = adapter_class || ActiveRecord::Base.connection.class
27+
base.include(Extensions)
3128
end
3229

3330
# Force reads for the supplied block to read from the primary database
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ActiveRecordReplica
2-
VERSION = '2.0.2'
2+
VERSION = '2.1.0'
33
end

0 commit comments

Comments
 (0)