rails migrations: handling naming conflicts

rake aborted!
Multiple migrations have the version number 119

If you work on any sizeable rails team, you’ve had someone check in a migration before you do. There’s a great timestamp-based solution by the folks at revolution on rails. That does seem to be pretty heavy-duty for a 2 person team though, so I have just been manually reverting migrations from console and the database shell.

So I decided to script it. Here is an automated rake task that handles my most common issue. I decided not to polish its rough edges, to let any ’standout candidates’ (TM) have a go at it (Standoutjobs is hiring). This task is barely tested; you probably shouldn’t use it unless you understand what it does. I’ll polish and test it later.

3 comments ↓

#1 Carl Mercier on 10.29.07 at 9:00 am

Daniel,

We run into this problem all the time! We’ll definitely look into that script. Thanks!

#2 macournoyer on RefactorMyCode.com on 10.29.07 at 4:57 pm

Rails migration conflict repair…

THis is the most useful rake task ever for a Rails user!
A couple of changes:
* rename to db:migrate:repair
* fix version on line 24 if more then one uncommitted migration
* invoke db:migrate at the end…

#3 danielharan on 01.15.08 at 12:58 pm

I finally got around to submitting this to rails-core:
http://dev.rubyonrails.org/ticket/10816

+1 if you’ve used it, thanks!

Leave a Comment