aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/tasks
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2018-03-16 14:04:09 -0400
committereileencodes <eileencodes@gmail.com>2018-03-21 14:00:58 -0400
commit5eb4488d02fd975ff5c387a8697fc58cca28b9b4 (patch)
tree9861f50547a0e08cb2347abea43b28c133c292af /activerecord/lib/active_record/tasks
parentd79d6867a23b90e0f9e2670a3300c9a044c84dca (diff)
downloadrails-5eb4488d02fd975ff5c387a8697fc58cca28b9b4.tar.gz
rails-5eb4488d02fd975ff5c387a8697fc58cca28b9b4.tar.bz2
rails-5eb4488d02fd975ff5c387a8697fc58cca28b9b4.zip
Add ability to create/drop/migrate all dbs for a given env
`each_current_configuration` is used by create, drop, and other methods to find the configs for a given environment and returning those to the method calling them. The change here allows for the database commands to operate on all the configs in the environment. Previously we couldn't slice the hashes and iterate over them becasue they could be two tier or could be three tier. By using the database config structs we don't need to care whether we're dealing with a three tier or two tier, we can just parse all the configs based on the environment. This makes it possible for us to run `bin/rails db:create` and it will create all the configs for the dev and test environment ust like it does for a two tier - it creates the db for dev and test. Now `db:create` will create `primary` for dev and test, and `animals` for dev and test if our database.yml looks like: ``` development: primary: etc animals: etc test: primary: etc animals: etc ``` This means that `bin/rails db:create`, `bin/rails db:drop`, and `bin/rails db:migrate` will operate on the dev and test env for both primary and animals ds.
Diffstat (limited to 'activerecord/lib/active_record/tasks')
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index af1bbc7e93..705a28eef5 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -261,8 +261,8 @@ module ActiveRecord
end
def load_schema_current(format = ActiveRecord::Base.schema_format, file = nil, environment = env)
- each_current_configuration(environment) { |configuration, configuration_environment|
- load_schema configuration, format, file, configuration_environment
+ each_current_configuration(environment) { |configuration, spec_name, env|
+ load_schema configuration, format, file, env
}
ActiveRecord::Base.establish_connection(environment.to_sym)
end
@@ -312,10 +312,10 @@ module ActiveRecord
environments = [environment]
environments << "test" if environment == "development"
- ActiveRecord::Base.configurations.slice(*environments).each do |configuration_environment, configuration|
- next unless configuration["database"]
-
- yield configuration, configuration_environment
+ environments.each do |env|
+ ActiveRecord::Base.configs_for(env) do |spec_name, configuration|
+ yield configuration, spec_name, env
+ end
end
end