Upgrading Rails Applications – Some things to keep in mind!

So we just went through this humongous (believe me!) effort ofupgrading the technical platform for one of our existing Railsapplications that was running Rails 2.1, Ruby 1.7 and Mongrel cluster.The goal was to upgrade to Rails 2.3, Enterprise Ruby 1.8.6 andPassenger. It all started out as well as you would think. Updating theRails gem, Ruby version, installing/configuring Passengerand updating relevant gems was pretty quick and smooth. Some quick anddirty testing of the application did not reveal any major problems orissues. Great! You are thinking the upgrade is mostly done att thispoint before you move on to the tests in the application!

Tests
Tests can prove to be major hurdle in upgrading Rails applications. In our specific case,  close to 70% of the tests were either broken orfailing due to a number of reasons.  Actually, the number of brokentests was way way greater than failing tests which led us to think thechanges in the Rails testing API caused most of these issues.  Some ofthe issues were also caused by a plugin or gem that was used to supportthe tests not being compatible with the new API. It took us quite a bitof effort to figure out the reasons for the issues and also find thefixes.

Plugins
I think this is other major pain point. If your application uses abunch of plugins to support what it does, then be wary of theroadblocks they can pose when it is time to upgrade Rails or Ruby inyour application.  The problem mostly arises because of the fact thatthe community or the user group that built the plugin dont continue tosupport it or doesnt bother to make it compatible with newer versionsof Ruby or Rails. In situations like these, you get thrown into a stateof dilemma thinking about whether to write a new plugin to replace theexisting one or fix the existing one both of which could betime-consuming.  It makes sense to spend time finding about whatexactly is the need for the plugin in the application and if it isindispensable etc before making a wise decision.

Deploying the upgraded application
Though this may not be as hairy as the first two, it could be stillprove to be a challenge especially when your the application server ischanging (Mongrel -> Passenger).  I think it is important to ensurethe script is modified appropriately and is tested adequately in yourstaging environment before you deploy the upgraded application to thereal-world.

Session handling issue with Rails 2.3
For the benefit of Rails community out there, I d like to brieflyrecount one of the problems that caused me a quite a bit of headacheduring the upgrade.  The application in question is a contentmanagement website with multiple subdomains. The issue that I saw afterthe upgrade was after user logged into the one of the subdomains in thesite and navigated away to a different subdomain, the user got loggedout. When the user returned to the subdomain where he logged inoriginally, he was logged in again.  After several hours of efforttrying to debug the issue (at one point,  I was even thinking aboutstripping out Restful authentication and plugging in Authlogic), this post saved the day for me.  It boiled down to setting this in the .rb file for the different environments :
config.action_controller.session = {
:domain => “”
}
This allowed the session information to be persisted across multiple subdomains of the site.

Some Advice

  • Generally, the amount of effort to upgrade is going to be directlyproportional to the time between the upgrades. So, upgrade yourapplication often!
  • When choosing plugins or gems to support your application, consider the upgradability of these before you decide to use them!
  • Last but not the least, spend atleast 25% of the time necessary forthe upgrade itself to estimate how long it might take to get it done 😉
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s