[Ruby] AR migration problems? was: refactoring/drying help

Ryan Davis ryand-ruby at zenspider.com
Fri Oct 12 11:23:13 PDT 2007


On Oct 11, 2007, at 16:37 , Jack Danger Canty wrote:

> In my current day job we've done significant rearrangements of the  
> schema at
> least a couple times. Migration #39 made perfect sense when we  
> created it
> but by #189 none of that model's relationships were named the same  
> thing
> (and most of them didn't even exist).  We brought someone in to  
> help out
> once and it was less than delightful to find out that he couldn't  
> run the
> migrations from version 0.

Yup. I deal with that with new clients nearly every time. It is  
almost always the first task that I do. It is very easy to clean up  
and get working. If on migration 39 you had a model MyThingy and by  
189 it is now called something Thingy, you only need to go back to 39  
and add:

	class MyThingy < ActiveRecord::Base; end

at the top of the file.

Start by making a rake task called 'nuke' that wipes the db and  
migrates. Run it. Make changes like the above until you've got a full  
run done. This makes it much much easier for someone new to come in  
and work on your stuff.

> I still use all the column management features of  
> ActiveRecord::Migration
> but I only use SQL for doing any sort of data management.

Sounds like a mess to me. I use the regular AR mechanisms unless I've  
got a simple data change to make where an SQL UPDATE would be loads  
faster.

> Bonus feature: the migrations are much smaller and a little faster.

and a little harder to maintain.



More information about the Ruby mailing list