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_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
# File 'lib/standby/connection_holder.rb', line 7

def activate(target)
  env_name = "#{ActiveRecord::ConnectionHandling::RAILS_ENV.call}_#{target}"
  if Standby.version_gte?('7.0')
    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