Rake just one migration

Viewed 75375

I'm trying to run just one migration out of a whole bunch in my rails app. How can I do this? I don't want to run any of the migrations before or after it. Thanks.

11 Answers

I use this technique in development when I change a migration a significant amount, and I don't want to migrate down a ton and lose any data in those along the way (especially when I'm importing legacy data that takes a long time that I don't want to have to re-import again).

This is 100% hackish and I would definitely not recommend doing this in production, but it will do the trick:

  1. Move migration that you want to re-run out of its directory to a temporary place
  2. Generate another migration with the same name
  3. Copy/paste the original migration code into the newly generated migration file
  4. Run the new migration
  5. Delete the newly generated migration file
  6. Edit your schema migrations to remove the most recent value
  7. Restore the old migration file
Related