detecting rake db:migrate ?

12 views
Skip to first unread message

Harold

unread,
Feb 5, 2009, 3:33:29 PM2/5/09
to Ruby on Rails: Talk
Hi group,

I have a line of code in environment.rb that cannot be run during a
rake db:migrate, as it depends on some tables being present.

I need to find a way to enclose this line in a check for db:migrate. I
know how to check if we're in a rake task with:

unless defined?(Rake)
# do stuff, but skip when run from rake tasks
end

How can I take this further to make check if I'm running the rake
db:migrate task?

Thanks,

-H

Harold

unread,
Feb 5, 2009, 3:51:10 PM2/5/09
to Ruby on Rails: Talk
Excuse me, the code I need to wrap around the check is on
ApplicationController. Still, any ideas?

Ryan Bigg

unread,
Feb 5, 2009, 4:22:46 PM2/5/09
to rubyonra...@googlegroups.com
There is a model class method like table_exists? That you can use to
check ifthe table exists and then only run the code if it does

Harold A. Giménez Ch.

unread,
Feb 5, 2009, 4:25:40 PM2/5/09
to rubyonra...@googlegroups.com
Thanks! That would work, for now.

I still have the itch though. If anyone knows, do tell.

Thanks again,
-H
Reply all
Reply to author
Forward
0 new messages