# Adding a prerequisite first to db:reset

**URL:** <https://www.ruby-forum.com/t/adding-a-prerequisite-first-to-db-reset/169870>\
**Category:** Rails\
**Created:** [June 9, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/adding-a-prerequisite-first-to-db-reset/169870 "2009-06-09T20:10:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![helix\_tp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@helix\_tp](https://www.ruby-forum.com/u/helix_tp)\
**Post date:** [June 9, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/adding-a-prerequisite-first-to-db-reset/169870/1 "2009-06-09T20:10:43Z")

</div>

I’m wondering if there was a better way to do this:

I want to add a prerequisite check to the db:reset rails task so that if  
we’re in production mode, the user has to add an additional environment  
variable for it to run (yes, I _know_ users shouldn’t even be on  
production machines, but in this case it’s worth it).

What I found I had to do was:

- added a task for the check:  
namespace :fp do  
task :check\_for\_production\_flag =\> :environment do  
raise “Boom!” unless RAILS\_ENV!=‘production’ || ENV[‘production’]  
end  
end

- added a dependency for db:reset:  
namespace :db do  
task :reset =\> [“fp:check\_for\_production\_flag”]  
end

And then, most importantly, had to change Rakefile so that the rake file  
with the above items was loaded _before_ “require ‘tasks/rails’”.

This _may_ be because db:reset is actually an empty task and  
accomplishes its work through its 3 prerequisites.

Did I have any alternative to doing it this way?

Thanks,

dwh
