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: do the migration inside my own rake task. I am confused about how to do this. Do I need a special request? My rake task will be in the lib / tasks directory of the Rails application. Thanks.

+3
source share
3 answers

Is your task simply dependent on having pure db? If this is the case, then you can do:

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

+2
source

EDIT: Rake:: Task [] , ENV. , .

ENV['VERSION']= '0'
Rake::Task['db:migrate'].invoke
Rake::Task['db:migrate'].reenable
ENV.delete 'VERSION'
Rake::Task["db:migrate"].invoke

. Rake:: Task.reenable Rake 0.8.2 .

+2

Check rake db:resetout as this will accomplish what you are trying to do.

To find out what all your rake tasks do, run rake -T

0
source

Source: https://habr.com/ru/post/1704210/


All Articles