What's a Dual Boot?
Tags: rails, upgrades, dualboot
Published: 2020-03-28 17:53:31

---
title: What's a Dual Boot?
published: true
description: A quick summary of using a dual boot to upgrade Rails and resources to learn more
tags: rails, upgrades, dual boot,
---

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 `next`. 

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. 

For example: 
```
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](https://github.com/clio/ten_years_rails)
  * 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 `if next?`
  * `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](https://github.blog/2018-09-28-upgrading-github-from-rails-3-2-to-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](https://engineering.shopify.com/blogs/engineering/upgrading-shopify-to-rails-5-0)
  * Shopify also used this strategy to upgrade, their journey is similar to Github's but a little different
  * They also have their own dual boot gem, [boot boot](https://github.com/Shopify/bootboot)
  * Also great from Shopify is [this talk by Rafael França](https://www.youtube.com/watch?v=I-2Xy3RS1ns) about their upgrade
* [How to Migrate Monotlith to the Scary New Version of Rails](https://dev.to/amplifr/how-to-migrate-monolith-to-the-scary-new-version-of-rails-3o52)
  * 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!