如何编写一个Rake任务来执行bundle install,然后执行rake db:migrate,最后执行rake db:seed?

4
如何编写一个 Rake 任务,以便先运行 bundle install,然后运行 rake db:migrate,最后运行 rake db:seed。
namespace 'install' do
  'bundle install'
  'rake db:migrate'
end
1个回答

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接