Update Rails from 5.1.7 to 5.2

Upgrading to Rails 5.2 succeeded

Last Updated on November 18, 2020 by Christopher G Mendla

Updating to Rails 5.2 has a couple of ‘gotchas’. 

Overview

I have a portfolio site hosted on Digital Ocean. This is a demo of my rails code and a bit of a sandbox to try things out. I’m currently in between jobs (Thanks Covid and shutdowns). I can use this app to keep my skills sharp.

Back it up. Repeat…. Back it up.

Before starting on the update, I created a snapshot of the server using Digital Ocean’s snapshot tool

If at first you don’t succeed. Try again

I had previously tried updating to Rails 5.2 and the result was that it worked in development but crashed production. I was able to recover the site back to 5.1.7.

Try Number 2

After I recovered the site and made sure everything was stable I tried the update again. I got the site back to Rails 5.1.7.

Deprecation warnings

Running Rspec was throwing some deprecation warnings. I fixed the warnings I could and left an issue on my GitHub repo.

Gem updates

I updated the Puma and PG gems.

Railsdiff

I always use Railsdiff when upgrading Rails. This keeps the code base clean and in sync with how it should look. I ran into a couple of files where the code in my app did not quite match the code in Railsdiff. That tool a little bit of analysis to see what should be changed.

Major Changes

Rails 5.2 has two major changes. The first is how it handles credentials and the second is how it handles storage. In addition there are a couple of other lesser changes.

Credentials

Rails 5.2 uses a new credentialing system. That caused one of the issues as I didn’t have that quite right. I decided to keep the old credentials for now by keeping the secrets.yml file.

I added an issue to the repo to migrate that at a later time. The old credential system worked.

ActiveStorage.

The other major change is the implementation of ActiveStorage to replace tools such as paperclip. For some reason that would throw an error in production. I removed the activestorage line from application.js and put another issue in the repo to revisit that.

The application doesn’t use the database at this time. I’m not sure if disabling activestorage would prevent the database from working or not.

Chromedriver/selenium etc.

There are changes to the testing support infrastructure. I got that running but have to revisit it.

Yarn

One of the other changes involves using Yarn. I had to install Yarn in my development environment and on the server. That forced me to straighten out the sudo rights on both dev and production. That was something I had been putting aside.

Is good enough the enemy of perfection or vice versa?

As you can see, I used a sledgehammer to get the site to Rails 5.2. I probably wouldn’t do that in a ‘real’ application. My goal is to get to Rails 5.4.2.2 to fix a vulnerability in prior versions of Rails. As a one person team doing this on the side I have to prioritize where I spend my effort.

Leave a Reply

Your email address will not be published. Required fields are marked *