ruby on rails rake task

for mongoid, since it doesn't support rake db:migrate and rake db:drop will drop all tables, so if we need to drop some of tables in database, I will the following code.

1. rails g task db droptables
2. in lib/tasks/db.rake file
namespace :db do
  desc "drop some seed tables"
  task droptables: :environment do
      Table1.destroy_all
      Table2.destroy_all
      Table3.destroy_all
...
  end
end

猜你喜欢

转载自j4s0nh4ck.iteye.com/blog/2226954