Module: ActiveRecord::Turntable::Migration::ShardDefinition

Defined in:
lib/active_record/turntable/migration.rb

Instance Method Summary collapse

Instance Method Details

#clusters(*cluster_names) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_record/turntable/migration.rb', line 15

def clusters(*cluster_names)
  config = ActiveRecord::Base.turntable_config
  (self.target_shards ||= []).concat(
    if cluster_names.first == :all
      config['clusters'].map do |name, cluster_conf|
        cluster_conf["shards"].map {|shard| shard["connection"]}
      end
    else
      cluster_names.map do |cluster_name|
        config['clusters'][cluster_name]["shards"].map do |shard|
          shard["connection"]
        end
      end.flatten
    end
  )
end

#shards(*connection_names) ⇒ Object



32
33
34
# File 'lib/active_record/turntable/migration.rb', line 32

def shards(*connection_names)
  (self.target_shards ||= []).concat connection_names
end