Forum: Ruby on Rails detecting rake db:migrate ?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Harold (Guest)
on 2009-02-05 22:33
(Received via mailing list)
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

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


Harold (Guest)
on 2009-02-05 22:55
(Received via mailing list)
Excuse me, the code I need to wrap around the check is on
ApplicationController. Still, any ideas?
Ryan B. (Guest)
on 2009-02-05 23:23
(Received via mailing list)
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. (Guest)
on 2009-02-05 23:26
(Received via mailing list)
Thanks! That would work, for now.

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

Thanks again,
This topic is locked and can not be replied to.