Forum: Ruby on Rails detecting rake db:migrate ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
53be54e5db4dc58e4980db5a8255621b?d=identicon&s=25 Harold (Guest)
on 2009-02-05 21: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
end

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

Thanks,

-H
53be54e5db4dc58e4980db5a8255621b?d=identicon&s=25 Harold (Guest)
on 2009-02-05 21:55
(Received via mailing list)
Excuse me, the code I need to wrap around the check is on
ApplicationController. Still, any ideas?
9a2a53db8e9b4476038c94a64b32833f?d=identicon&s=25 Ryan Bigg (ryan-bigg)
on 2009-02-05 22: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
53be54e5db4dc58e4980db5a8255621b?d=identicon&s=25 Harold A. Giménez Ch. (Guest)
on 2009-02-05 22:26
(Received via mailing list)
Thanks! That would work, for now.

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

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