使用rake任务重置数据库

我想每天使用Heroku的调度程序重置一次数据库。

建议对调度程序使用rake任务。 这就是我尝试过的:

task :reset_database => :environment do `heroku pg:reset MY_DB:URL` `heroku run rake db:migrate db:seed` # some other ruby commands end 

但是我怎么能正确地做到这一点,因为将heroku命令放在反引号中,而bash 正常工作 ,这在这里不起作用:

No such file or directory - heroku

尝试这个rake任务:

 namespace :reset_database do desc "Destroy all table entries." task :all => :environment do ActiveRecord::Base.connection.tables.each do |table| if table != 'schema_migrations' table.singularize.camelize.constantize.destroy_all end # Use this if you want to use the normal seeds: # Rails.application.load_seed # Use this if you want to run another rake task: Rake::Task["foo:bar"].invoke end end end