diff options
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" |