Home > Code, Ruby on Rails > Easy Solution for Conflicting Rails Migration Version Numbering

Easy Solution for Conflicting Rails Migration Version Numbering

migrations numbers
Thats a crappy blog post title but the best I could come up with! You know the scenario: you are about to commit your latest Rails code to subversion and you perform an update first. Rats. Someone has committed a new migration with the same number as yours. So you mess around with SQL manually reversing changes, and rename files. Its a pain, and I think this single problem with Rails causes much stress because as Rails developers we are used to everything working so smoothly. We’ll Steve Purcell has solved this problem in a beautiful way.

Install his plugin ‘renumber_migrations’:
script/plugin install http://rails.sanityinc.com/plugins/renumber_migrations/

Next time you run into this migrations mess:
rake db:migrate:renumber

Problem solved!

One note: for some reason I couldn’t get it to work until I removed line 18:
raise "This task currently supports only subversion projects"

Don’t know why he added that line but once it was removed it worked perfectly. Thank you very much Steve! Now if someone will write a nice script to setup a bunch of common ignore properties (log/, schema.rb, tmp/) in SVN when first importing a new Rails project…. :)

Categories: Code, Ruby on Rails Tags:
  1. March 2nd, 2008 at 13:07 | #1

    Hi Tony – thanks for your kind words about the plugin.

    I’ve fixed the embarrassing error you encountered; I think it’s from when I was working on getting the plugin working for git projects, and wanted some sort of sanity checking. Doh.