Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
show all
- Defined in:
- lib/multi_db/active_record_patches.rb
Class Method Summary
collapse
Class Method Details
.connect_to_master ⇒ Object
21
22
23
|
# File 'lib/multi_db/active_record_patches.rb', line 21
def connect_to_master
self.establish_connection(master_configuration)
end
|
.connect_to_organization(org = nil, set_env = false) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/multi_db/active_record_patches.rb', line 25
def connect_to_organization(org = nil, set_env = false)
org_code = org.is_a?(MultiDB::Organization) ? org.code : org
org_code ||= ENV['RAILS_ORG'] || 'org1'
config = ActiveRecord::Base.configurations[Rails.env]
self.establish_connection(config.merge('database' => "#{config['database']}_#{org_code}"))
begin
ActiveRecord::Base.connection.tables
rescue Mysql2::Error
Rails.logger.error "Couldn't connect to org db for #{org_code}"
return false
end
ENV['RAILS_ORG'] = org_code if set_env
org_code
end
|
.connect_to_sessions ⇒ Object
16
17
18
19
|
# File 'lib/multi_db/active_record_patches.rb', line 16
def connect_to_sessions
config = configurations[Rails.env || 'development']
self.establish_connection(config)
end
|
.master_configuration(env = nil) ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/multi_db/active_record_patches.rb', line 5
def master_configuration(env = nil)
env ||= Rails.env
configurations["master_#{env}"] or Proc.new {
c = configurations[env].dup
c['database'] += '_master'
c
}.call
end
|