如何编写一个 Rake 任务,以便先运行 bundle install,然后运行 rake db:migrate,最后运行 rake db:seed。
namespace 'install' do
'bundle install'
'rake db:migrate'
end
namespace 'install' do
'bundle install'
'rake db:migrate'
end
这应该是可行的,但考虑使用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