Module: ActiveRecord::Tasks::DatabaseTasks
- Defined in:
- lib/active_record/turntable/active_record_ext/database_tasks.rb
Instance Method Summary collapse
- #create_all_turntable_cluster ⇒ Object
- #create_current_turntable_cluster(environment = env) ⇒ Object
- #current_turntable_cluster_configurations(*environments) ⇒ Object
- #drop_all_turntable_cluster ⇒ Object
- #drop_current_turntable_cluster(environment = env) ⇒ Object
- #each_current_turntable_cluster_configuration(environment) ⇒ Object
- #each_current_turntable_cluster_connected(environment) ⇒ Object
- #each_local_turntable_cluster_configuration ⇒ Object
Instance Method Details
#create_all_turntable_cluster ⇒ Object
6 7 8 9 10 11 |
# File 'lib/active_record/turntable/active_record_ext/database_tasks.rb', line 6 def create_all_turntable_cluster each_local_turntable_cluster_configuration { |_name, configuration| puts "[turntable] *** executing to database: #{configuration['database']}" create configuration } end |
#create_current_turntable_cluster(environment = env) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/active_record/turntable/active_record_ext/database_tasks.rb', line 20 def create_current_turntable_cluster(environment = env) each_current_turntable_cluster_configuration(environment) { |_name, configuration| puts "[turntable] *** executing to database: #{configuration['database']}" create configuration } ActiveRecord::Base.establish_connection environment.to_sym end |
#current_turntable_cluster_configurations(*environments) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/active_record/turntable/active_record_ext/database_tasks.rb', line 70 def current_turntable_cluster_configurations(*environments) configurations = [] environments.each do |environ| config = ActiveRecord::Base.configurations[environ] next unless config %w(shards seq).each do |name| configurations += config[name].to_a if config.has_key?(name) end end configurations end |
#drop_all_turntable_cluster ⇒ Object
13 14 15 16 17 18 |
# File 'lib/active_record/turntable/active_record_ext/database_tasks.rb', line 13 def drop_all_turntable_cluster each_local_turntable_cluster_configuration { |_name, configuration| puts "[turntable] *** executing to database: #{configuration['database']}" drop configuration } end |
#drop_current_turntable_cluster(environment = env) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/active_record/turntable/active_record_ext/database_tasks.rb', line 28 def drop_current_turntable_cluster(environment = env) each_current_turntable_cluster_configuration(environment) { |_name, configuration| puts "[turntable] *** executing to database: #{configuration['database']}" drop configuration } end |
#each_current_turntable_cluster_configuration(environment) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/active_record/turntable/active_record_ext/database_tasks.rb', line 47 def each_current_turntable_cluster_configuration(environment) environments = [environment] environments << "test" if environment == "development" current_turntable_cluster_configurations(*environments).each do |name, configuration| yield(name, configuration) unless configuration["database"].blank? end end |
#each_current_turntable_cluster_connected(environment) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/active_record/turntable/active_record_ext/database_tasks.rb', line 35 def each_current_turntable_cluster_connected(environment) old_connection_pool = ActiveRecord::Base.connection_pool each_current_turntable_cluster_configuration(environment) do |name, configuration| ActiveRecord::Base.clear_active_connections! ActiveRecord::Base.establish_connection(configuration) ActiveRecord::Migration.current_shard = name yield(name, configuration) end ActiveRecord::Base.clear_active_connections! ActiveRecord::Base.establish_connection old_connection_pool.spec.config end |
#each_local_turntable_cluster_configuration ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/active_record/turntable/active_record_ext/database_tasks.rb', line 56 def each_local_turntable_cluster_configuration ActiveRecord::Base.configurations.keys.each do |k| current_turntable_cluster_configurations(k).each do |name, configuration| next if configuration["database"].blank? if local_database?(configuration) yield(name, configuration) else $stderr.puts "This task only modifies local databases. #{configuration['database']} is on a remote host." end end end end |