aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRoberto Miranda <rjmaltamar@gmail.com>2019-03-27 15:12:00 +0000
committerRoberto Miranda <rjmaltamar@gmail.com>2019-03-27 15:16:00 +0000
commitaf9b2af7195b2c685dac2e0a6ca9d26e884928e7 (patch)
tree724d0c5b04a0ded205319c728b157ef7ee81cbb3 /activerecord
parent3c2f3010785d8061415dbb3bac04be312123b931 (diff)
downloadrails-af9b2af7195b2c685dac2e0a6ca9d26e884928e7.tar.gz
rails-af9b2af7195b2c685dac2e0a6ca9d26e884928e7.tar.bz2
rails-af9b2af7195b2c685dac2e0a6ca9d26e884928e7.zip
Add rake db:prepare rake task.
It Creates the database, loads the schema, run the migrations and initializes with the seed data (use db:reset to also drop the database first). This rake task runs in an idempotent way ref https://github.com/rails/rails/pull/33139#discussion_r195930751
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/railties/databases.rake8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index f021a8f6c4..ee3668e1a9 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -222,6 +222,14 @@ 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 "Creates the database, loads the schema, run the migrations and initializes with the seed data (use db:reset to also drop the database first)"
+ task prepare: :load_config do
+ ActiveRecord::Base.connection
+ db_namespace["migrate"].invoke
+ rescue ActiveRecord::NoDatabaseError
+ db_namespace["setup"].invoke
+ end
+
desc "Loads the seed data from db/seeds.rb"
task seed: :load_config do
db_namespace["abort_if_pending_migrations"].invoke