Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I code a rake task that runs the Rails db:migrate task?

I would like to run db:migrate VERSION=0 and then db:migrate inside of my own rake task. I am confused about how to do this. Do I need a special require statement? My rake task will reside in the lib/tasks directory of a Rails app. Thanks.

like image 622
fooledbyprimes Avatar asked Feb 02 '26 00:02

fooledbyprimes


1 Answers

Is your task just dependent on having a clean db? If that's the case then you can do:

task :my_task => [:environment, 'db:reset']

like image 58
Mike Breen Avatar answered Feb 03 '26 15:02

Mike Breen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!