Execute a Rake task from within migration?

Yes there’s a way to do that:

Rake::Task['your_task'].invoke

Update

Do not put rake inside the brackets, just the name of the task. You should set an ENV variable when running this:

In the console

FILE=somefile.text rake db:sistema:load_data

Calling it separately

FILE=somefile.text rake some:other:task:that:calls:it

This will be available in your tasks as ENV['file']

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)