![](/img/trans.png)
[英]In a Rails app running on multiple servers, how can I make sure a rake task runs only once?
[英]How can you make a rake task that makes changes in multiple environments?
我有一個rake任務,用於填充開發數據庫。 完成后,我希望它也重置測試數據庫,但是我無法弄清楚語法。 我需要這樣的東西:
namespace :db do
task populate: :environment do
Rake::Task["db:reset"].execute
Rake::Task["db:reset"].execute RAILS_ENV=test
# Add lots of data to the :environment database
end
end
這使我可以運行rake db:populate
以使用最新架構填充開發數據庫,並重置測試數據庫。
任務db:test:clone_structure
將重置測試數據庫架構以匹配開發數據庫架構
namespace :db do
task populate: :environment do
Rake::Task["db:reset"].execute
Rake::Task["db:test:clone_structure"].execute
# Add lots of data to the :environment database
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.