Module: ActiveRecord::ShardFor::DatabaseTasks

Extended by:
TaskOrganizerForSingleClusterTask, TasksForMultipleClusters, TasksForSingleConnection
Defined in:
lib/activerecord/shard_for/database_tasks.rb

Defined Under Namespace

Modules: TaskOrganizerForSingleClusterTask, TasksForMultipleClusters, TasksForSingleConnection

Class Method Summary collapse

Methods included from TasksForMultipleClusters

invoke_task, invoke_task_for_all_clusters

Methods included from TaskOrganizerForSingleClusterTask

create_all_databases, drop_all_databases, load_schema_all_databases

Methods included from TasksForSingleConnection

create, drop, load_schema

Class Method Details

.ar417_above?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/activerecord/shard_for/database_tasks.rb', line 32

def ar417_above?
  ar41? && ActiveRecord::VERSION::TINY > 7
end

.ar41?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/activerecord/shard_for/database_tasks.rb', line 27

def ar41?
  ar4? && ActiveRecord::VERSION::MINOR == 1
end

.ar42?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/activerecord/shard_for/database_tasks.rb', line 22

def ar42?
  ar4? && ActiveRecord::VERSION::MINOR == 2
end

.ar4?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/activerecord/shard_for/database_tasks.rb', line 17

def ar4?
  ActiveRecord::VERSION::MAJOR == 4
end

.ar5?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/activerecord/shard_for/database_tasks.rb', line 12

def ar5?
  ActiveRecord::VERSION::MAJOR == 5
end

.ar6?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/activerecord/shard_for/database_tasks.rb', line 7

def ar6?
  ActiveRecord::VERSION::MAJOR == 6
end

.cluster_namesArray<Symbol>

Returns:

  • (Array<Symbol>)


58
59
60
# File 'lib/activerecord/shard_for/database_tasks.rb', line 58

def cluster_names
  ActiveRecord::ShardFor.config.cluster_configs.keys
end

.clustersArray<ActiveRecord::ShardFor::ClusterConfig>



64
65
66
# File 'lib/activerecord/shard_for/database_tasks.rb', line 64

def clusters
  ActiveRecord::ShardFor.config.cluster_configs.values
end

.exit_with_errorObject

For mock-ablity



77
78
79
# File 'lib/activerecord/shard_for/database_tasks.rb', line 77

def exit_with_error
  exit 1
end

.fetch_cluster_config(cluster_name) ⇒ ActiveRecord::ShardFor::ClusterConfig

Returns:

Raises:

  • (KeyError)


71
72
73
# File 'lib/activerecord/shard_for/database_tasks.rb', line 71

def fetch_cluster_config(cluster_name)
  ActiveRecord::ShardFor.config.fetch_cluster_config(cluster_name)
end

.infoObject

Show information of database sharding config.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/activerecord/shard_for/database_tasks.rb', line 37

def info
  puts 'All clusters registered to ActiveRecord::ShardFor'
  puts
  clusters.each do |cluster|
    puts "= Cluster: #{cluster.name} ="
    cluster.connections.each do |name|
      puts "- #{name}"
    end
    puts
  end
end

.to_rake_task(task_name) ⇒ Rake::Task

Parameters:

  • task_name (String)

Returns:

  • (Rake::Task)


52
53
54
# File 'lib/activerecord/shard_for/database_tasks.rb', line 52

def to_rake_task(task_name)
  Rake::Task[task_name]
end