module ActiveRecord::ShardFor::DatabaseTasks::TaskOrganizerForSingleClusterTask

Organize cluster config and handle error for invalid args, call single cluster task with each single connection config.

Public Instance Methods

create_all_databases(args) click to toggle source

@param [Hash{Symbol => String}] args

# File lib/activerecord/shard_for/database_tasks.rb, line 104
def create_all_databases(args)
  exec_task_for_all_databases('create', args)
end
drop_all_databases(args) click to toggle source

@param [Hash{Symbol => String}] args

# File lib/activerecord/shard_for/database_tasks.rb, line 109
def drop_all_databases(args)
  exec_task_for_all_databases('drop', args)
end
load_schema_all_databases(args) click to toggle source

@param [Hash{Symbol => String}] args

# File lib/activerecord/shard_for/database_tasks.rb, line 114
def load_schema_all_databases(args)
  exec_task_for_all_databases('load_schema', args)
end

Private Instance Methods

cluster_name_or_error(name, args) click to toggle source

@param [String] name A task name @param [Hash{Symbol => String}] args @return [String]

# File lib/activerecord/shard_for/database_tasks.rb, line 133
        def cluster_name_or_error(name, args)
          cluster_name = args[:cluster_name]
          return cluster_name if cluster_name

          $stderr.puts <<-MSG
  Missing cluster_name. Find cluster_name via `rake activerecord:shard_for:info` then call `rake "activerecord:shard_for:#{name}[$cluster_name]"`.
          MSG
          exit_with_error
        end
cluster_or_error(cluster_name) click to toggle source

@param [String] cluster_name @return [ActiveRecord::ShardFor::ClusterConfig]

# File lib/activerecord/shard_for/database_tasks.rb, line 145
def cluster_or_error(cluster_name)
  fetch_cluster_config(cluster_name.to_sym)
rescue KeyError
  $stderr.puts %(!cluster name "#{cluster_name}" not found.!)
  exit_with_error
end
exec_task_for_all_databases(task_name, args) click to toggle source

@param [String] task_name @param [Hash{Symbol => String}] args

# File lib/activerecord/shard_for/database_tasks.rb, line 122
def exec_task_for_all_databases(task_name, args)
  cluster_name = cluster_name_or_error(task_name, args)
  cluster = cluster_or_error(cluster_name)
  cluster.connections.each do |connection_name|
    __send__(task_name, connection_name.to_s)
  end
end