Class: Standby::ConnectionHolder

Inherits:
ActiveRecord::Base show all
Defined in:
lib/standby/connection_holder.rb

Class Method Summary collapse

Methods inherited from ActiveRecord::Base

connection, connection_pool, connection_pool_without_standby, connection_without_standby, on_standby

Class Method Details

.activate(target) ⇒ Object

for delayed activation

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/standby/connection_holder.rb', line 7

def activate(target)
  env_name = "#{ActiveRecord::ConnectionHandling::RAILS_ENV.call}_#{target}"
  # Rails 6.1+ exposes DatabaseConfigurations helpers; older versions still use hash access.
  if ActiveRecord::Base.configurations.respond_to?(:find_db_config)
    spec = ActiveRecord::Base.configurations.find_db_config(env_name)&.configuration_hash
  else
    spec = ActiveRecord::Base.configurations[env_name]
  end
  raise Error, "Standby target '#{target}' is invalid!" if spec.nil?

  establish_connection spec
end