To organize database for my Ruby on Rails 3 application I have to run the next stages in the Terminal:
rake db:create rake db:migrate rake db:seed
Can you really do all individuals stages in one? Maybe it's possible managing a 'rake' command which will "fire" another 'rake' command... but exactly how?!
You are able to define your personal rake tasks which call other tasks as requirements:
# lib/tasks/my_tasks.rake namespace :db do desc "create, migrate and seed" task :do_all => [:create,:migrate,:seed] do end end
Normally your body from the task would contain Ruby code to behave, however in this situation we're just invoking the 3 prerequisite tasks consequently (
rake db:create db:migrate db:seed is going to do everything.
The empty do-finish blocks aren't needed, e.g. (for zetetic's answer)
$ cat lib/tasks/my_tasks.rake # lib/tasks/my_tasks.rake namespace :db do desc "create, migrate and seed" task :do_all => [:create,:migrate,:seed] end
zeteitic first got it right, but in case you don't wish to namespace this under "db", you will want something a lot more like this:
desc "Bootstrap database." task :bootstrap => ["db:create", "db:migrate", "db:seed"] do; end
As well as on the command line:
rake bootstrap # => create, migrate and seed db