aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/railties
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/railties
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/railties')
-rw-r--r--activerecord/lib/active_record/railties/databases.rake7
1 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index 176e617258..787c5f7a5c 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -73,8 +73,11 @@ db_namespace = namespace :db do
desc "Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)."
task migrate: :load_config do
- ActiveRecord::Tasks::DatabaseTasks.migrate
- db_namespace["_dump"].invoke
+ ActiveRecord::Base.configs_for(Rails.env) do |spec_name, config|
+ ActiveRecord::Base.establish_connection(config)
+ ActiveRecord::Tasks::DatabaseTasks.migrate
+ db_namespace["_dump"].invoke
+ end
end
# IMPORTANT: This task won't dump the schema if ActiveRecord::Base.dump_schema_after_migration is set to false