This should be in a Rake task: http://railscasts.com/episodes/66-custom-rake-tasks