# Running rake commands from rake migrate

**URL:** <https://www.ruby-forum.com/t/running-rake-commands-from-rake-migrate/53036>\
**Category:** Rails\
**Created:** [January 23, 2006, 6:05pm UTC](https://www.ruby-forum.com/t/running-rake-commands-from-rake-migrate/53036 "2006-01-23T18:05:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@Jason\_E](https://www.ruby-forum.com/u/Jason_E)\
**Post date:** [January 23, 2006, 6:05pm UTC](https://www.ruby-forum.com/t/running-rake-commands-from-rake-migrate/53036/1 "2006-01-23T18:05:40Z")

</div>

Hi there,

How can I run rake commands from a rake migration? I’m looking to run  
rake engine\_migrate and others commands from a migration in order to  
migrate my engines along with my core app. Any advice is appreciated.

Thanks,  
Jason

---

<div class="post-metadata">

**Author:** ![Jason\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@Jason\_E](https://www.ruby-forum.com/u/Jason_E)\
**Post date:** [January 23, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/running-rake-commands-from-rake-migrate/53036/2 "2006-01-23T18:11:43Z")

</div>

You could just include the task in the dependencies for your new task,  
i.e.

—RAILS\_ROOT/lib/tasks/app.rake—

desc ‘Migrate entire application’  
task :app\_migrate =\> [:migrate, :engine\_migrate]

… I think it might actually be that simple.

- james

---

<div class="post-metadata">

**Author:** ![Jason\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@Jason\_E](https://www.ruby-forum.com/u/Jason_E)\
**Post date:** [January 23, 2006, 8:01pm UTC](https://www.ruby-forum.com/t/running-rake-commands-from-rake-migrate/53036/3 "2006-01-23T20:01:41Z")

</div>

hi,

Thanks for the info. It’s not quite what I need though.

I’m switching from login\_generator to login\_engine and I need to be able  
to drop the incompatible user table, then run rake engine\_migrate and  
rake bootstrap and others to set up user\_engine and login\_engine.

Thanks,  
Jason

---

<div class="post-metadata">

**Author:** ![Jason\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@Jason\_E](https://www.ruby-forum.com/u/Jason_E)\
**Post date:** [January 23, 2006, 10:18pm UTC](https://www.ruby-forum.com/t/running-rake-commands-from-rake-migrate/53036/4 "2006-01-23T22:18:49Z")

</div>

I found the answer to my own question and decided to post it.

The answer is here:  
[http://thinkingincode.blogspot.com/2005/12/adding-options-to-rake-tasks.html](http://thinkingincode.blogspot.com/2005/12/adding-options-to-rake-tasks.html)

Rake::Task[:engine\_migrate].invoke

will run a rake task from within a migration and other ruby code. rake  
takes it’s options from ENV[].

to run “rake engine\_migrate ENGINE=user” do

ENV[“ENGINE”]=“user”  
Rake::Task[:engine\_migrate].invoke

FYI,  
Jason
