diff options
author | Roberto Miranda <rjmaltamar@gmail.com> | 2019-04-02 15:11:09 +0100 |
---|---|---|
committer | Roberto Miranda <rjmaltamar@gmail.com> | 2019-04-02 16:25:48 +0100 |
commit | 098e4d25f19f2b932841401fdc5e7340876d8ff2 (patch) | |
tree | 5087c84b4ec929db58b9663059fa0f92b927a8a0 /activerecord/lib | |
parent | 8375b8ee6da72152193df409c91f7f35f71b6836 (diff) | |
download | rails-098e4d25f19f2b932841401fdc5e7340876d8ff2.tar.gz rails-098e4d25f19f2b932841401fdc5e7340876d8ff2.tar.bz2 rails-098e4d25f19f2b932841401fdc5e7340876d8ff2.zip |
Add test cases for rake db:prepare
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index b022fe942a..ef8292de2b 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -222,13 +222,16 @@ db_namespace = namespace :db do desc "Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)" task setup: ["db:schema:load_if_ruby", "db:structure:load_if_sql", :seed] - desc "Setup database if doesn’t exist already and run migrations" + desc "Runs setup if database does not exist, or runs migrations if it does" task prepare: :load_config do - ActiveRecord::Base.connection - rescue ActiveRecord::NoDatabaseError - db_namespace["setup"].invoke - else - db_namespace["migrate"].invoke + ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| + begin + ActiveRecord::Base.establish_connection(db_config.config) + db_namespace["migrate"].invoke + rescue ActiveRecord::NoDatabaseError + db_namespace["setup"].invoke + end + end end desc "Loads the seed data from db/seeds.rb" |