rubyrakerollbackrake-taskrakefile

Implement rake db:rollback STEP=n inside rakefile


I'm trying to combine a bunch of rake tasks like this:

desc 'Resets the database'
task :reset do
  Rake::Task["db:rollback"].invoke
  Rake::Task["db:migrate"].invoke
  Rake::Task["db:seed"].invoke
end

I don't know how to do rollback with STEP=n inside my Rakefile


Solution

  • STEP is an environment variable, so if you do this:

        desc 'Resets the database'
        task :reset do
          ENV['STEP'] = '1000' 
    # The number has to be greater than
    # or equal to the number of your migrations.
    
          Rake::Task["db:rollback"].invoke
          Rake::Task["db:migrate"].invoke
          Rake::Task["db:seed"].invoke
        end
    

    that should work