I was recently asked about using a dual boot strategy for Rails upgrades and thought I'd share my response as a blog post in case others may be interested in a high-level overview of the approach.
I'd highly recommend this strategy for an application upgrade if the entire development can't stop feature development and shift their focus to the upgrade.
The idea behind a dual boot is to have two Gemfiles, one the contains the current, production application's dependencies. The other contains the dependencies required for an upgrade, often referred to as
The code that differs between the old and next versions of Rails is activated by a conditional that uses a method, normally named
next? to determine which part should be running.
if next? # code compatible with the next version of Rails else # existing code that works for the app's current version of Rails end
After the dual Gemfiles are set up, run the test suite in the
next version and start fixing specs, adding conditionals where necessary to get the code to run on the next version. Check your changes by running the test suite on the current version to make sure that something that was fixed didn't inadvertently break something that was working on the live app.
Everyone's work is done branched off of master, so there's no messy rebasing or git pulling practices that need to be in place to balance the upgrade team's work with the feature team's work.
Here are some resources I found helpful while implementing a dual boot for a Rails 2 to Rails 4 upgrade:
Ten Years Rails Gem
- Creates a symlinked Gemfile.next to have two separate bundles, one for the current version of Rails and the other for the version you're upgrading to
- To separate code activated on the old version vs. the upgraded version, wrap the code in a conditional statement
next?changes the BUNDLE_GEMFILE to use the Gemfile.next versions
- There's a talk linked on the repo I'd recommend watching
Upgrading Github from Rails 3.2 to Rails 5.2
- Written by Eileen Uchitelle who led the upgrade effort. They used a dual boot and now run the app off of Rails master
- She's given a lot of podcast interviews as well, Google her name for more resources
- Upgrading Shopify to Rails 5
How to Migrate Monotlith to the Scary New Version of Rails
- Excellent breakdown of how the dual boot works, with more awesome links at the end
Do you have any questions about dual booting? What are your favorite Rails upgrade tips and strategies? Post them below!