Darwinweb

Specifying an Explicit ActiveRecord Version in Merb

June 23, 2008     

Last night, I needed to make a quick update to my merb app’s schema. Nothing fancy. This is my first update since Rails 2.1 dropped with it’s improved migration naming scheme. For whatever reason rake db:migrate did not work as smoothly as it did in Rails. Since I was on a short deadline I decided to revert to ActiveRecord 2.0.2 rather than debug the actual problem. I figured this ought to be pretty trivial right?

I’m still very much a Merb newbie, but it wasn’t too hard to figure out to put this in my init.rb:

dependency "activerecord", "= 2.0.2"

As long as it appears before the use_orm line it does what it’s supposed to. Well, at least it does when you run merb start. However my problem was with rake db:migrate which now had a new problem:

can't activate activesupport (= 2.0.2), already activated activesupport-2.1.0]

I tried several solutions including requiring activesupport 2.0.2 explicitly and installing the specific gems into ./gems. Same problem. Obviously there was a problem before the Merb invocation. Turns out the Rakefile requires rubigen which in turn requires activesupport.

Okay, no big deal, just add this somewhere above rubigen in the Rakefile:

gem "activesupport", "= 2.0.2"

Now the Merb app and rake tasks work, but a quick test reveals merb-gen is now borked same as rake was. Same error, same cause. Problem is ActiveSupport is required in the very first file which is part of the official release at /usr/local/bin/merb-gen. So to actually solve this problem you need to specify the ActiveSupport version in that executable file.

At this point I’m starting to think I should have debugged the original problem and submitted a patch to fix it, but I’ve got a working fix which is what I need right now, so I duplicate the file into my working directory and add the fix.

All this has me reflecting on the difficulties of dependency management, and the value of stable public interfaces. The general case seems very hard to manage, but I can think of some solutions at the Merb level. Hmm, maybe my first Merb patch?