Running rake in production mode

This is the second time now that this has had me tearing my hair out. Last time, I couldn’t work out how to get rake db:migrate to operate on the production database. After a while on Google, I managed to find:

%> rake --require=config/environment.rb db:migrate

It worked like a treat, even on the Windows server my app’s deployed on (though with \ as the path separator, not /).

Until now, that is.

I’ve just switched to using the paginating_find plugin for paging result sets, as it allows me to use all the find options, unlike the rails default pagination. It works fine in both development and production, and rake is happy in development mode. It doesn’t like the command above, though, if you happen to call the find method in your migration. For some bizarre reason, the find method aliasing goes wrong, and you get an infinite loop. The overwritten find method is supposed to call the original find method, but ends up calling itself recursively instead.

Back to Google… nothing on this problem that I could find.

Rethink: it must be something with the way production mode is specified, since it’s only a problem when running rake like this.

Back to Google again: this time to look for alternative methods to specify that rake should use the production environment. Finally found a way, thanks to a post on a TextDrive forum:

%> RAILS_ENV=production rake db:migrate

That solves the problem on Linux, how about on Windows?

%> set RAILS_ENV=production
%> rake db:migrate

Sorted!

3 Responses to “Running rake in production mode”

  1. Toy Maker Says:

    Thanks for this tutorial. I was looking all over for how to get my migrations to work for production mode. Your article was the only one I found that had this information. It worked like a charm.

  2. za3tar Says:

    Thanks for the tip. I have been facing this problem as well, tearing my hair and everything :-) … this time around, Google found your page ;-)

  3. Daniela Says:

    Thanks Rebecca,
    just what I needed to know!
    Daniela

Leave a Reply