Revisiting rails:update

06 Aug 2015

Lately I've been revisiting some Rails apps which have been around for a while. These are Rails apps that started life somewhere in the 2.x era and are now on the latest (4.2.3 as of this writing), and they were upgraded in a series of steps over the past couple of years. So all that to say that these apps have been through a lot of changes.

When I'm doing Rails upgrades I tend to do the minimum necessary to get the app to the next version. Then I make some notes on things to revisit after the dust has settled. Sometimes those things happen, sometimes not. One thing I hadn't done before is run rake rails:update on those apps. I had tried it a couple of times, but I would see a huge diff and shelve it for later.

But I think I was approaching it in the wrong way. Here's what I've been doing lately.

bundle exec rake rails:update # and hit 'a' to accept all changes
git diff > ../rails_update.diff
git add . && git reset --hard # throw changes away
git checkout -b newify

Now in a terminal window I more ../rails_update.diff and just kind of page through it, looking for useful bits and fixing them as I go. Stuff like:

There are usually some other things I spot when poking through these files - old constant settings, old environment variable checks, etc. Usually a git blame will help me figure out if this is something that was added 5 years ago and never deleted or will at least let me know who I can talk to about it.

None of these changes are big wins, it's just a few milliseconds here and there. But they all add up and help to make an old and crufty application more approachable. Plus, red commits always feel good!

Thanks to Jeremy Stuckey for reviewing this post.