如何写一个rake任务来捆绑安装然后rake db:migrate然后rake db:seed?

时间:2011-09-12 06:22:16

标签: ruby-on-rails rake

如何编写一个rake任务,将捆绑安装然后rake db:migrate然后rake db:seed。

namespace 'install' do
  'bundle install'
  'rake db:migrate'
end

1 个答案:

答案 0 :(得分:4)

这应该可以,但考虑使用Capistrano / Chef进行部署:

namespace :install do
  task :db_reset do
    # bundle install - I do not believe attempting this in a rake file
    # is recommended as one would need to ensure it is run in your application
    # directory and rvm has loaded correct version of ruby/gemsets (.rvmrc required)
    Rake::Task['db:migrate'].invoke
  end
end

或者,您可以设置shell别名来执行

bundle install && bundle exec rake db:migrate && bundle exec rake db:seed