Friday, July 6, 2007

How To Use Rails Migrations From The Console

Sometimes you want to run a Rails migration in only one environment. Say for the sake of argument you have a messy legacy app and you need to add database sessions immediately, without going into the cleanup you have to do on the development environment side.

There's probably a more elegant way to do this, but this is the quick and dirty shortcut.

(Got the idea from the Rails wiki.)

4 comments:

  1. Would
    rake db:migrate RAILS_ENV=production
    be sufficient? That appears to be the end result of your script.

    ReplyDelete
  2. hahahahaha

    doh.

    yes. that would probably work.

    ReplyDelete
  3. and VERSION= if you need to specify that too. ;)

    ReplyDelete
  4. Just a thing here - my initial response seems kind of painfully inane to me. So, yes, Matt's solution is the right way to do it. This is just how you do it in a hurry. If you're working with Mongrel, migrations, and the console, you've got to remember that one takes -e production, another RAILS_ENV=production, and another simply the quoted string 'production'. The whole point of working with shell aliases and the console is speed and productivity.

    I couldn't remember which of those command-line options was which. Ironically, for this particular case, posting the wrong thing in your blog actually turns out to be a more efficient way of finding the answer than looking it up via Google.

    ReplyDelete

Note: Only a member of this blog may post a comment.