See all articles

5 things to consider when upgrading the Rails application

Paweł Dąbrowski-Chief Technology Officer

When planned properly, software upgrades are easier and less time-consuming than we expect them to be. In this article, we cover a few essential steps, you can’t forget about when approaching an upgrade of your Rails app.

Over the years, we upgraded tens of Rails applications. Some of the upgrades were more complex than others, especially in cases when we started with a very old version of a legacy codebase and gradually upgraded it to meet the recent standards. No matter the complexity and size of the application, the upgrades always resulted in a more stable system, as well as faster and easier development of new features.

Let’s go through five essential steps, you shouldn’t omit when upgrading your Rails application.

Always start with the plan

Since timelines for software development are difficult to predict, most programmers dislike doing estimations and planning. The time between an initial estimate and delivery can be filled with many surprises. Despite that, we always begin projects with an estimate, regardless of whether we are doing the upgrade for a client or internally.

Drafting a plan forces you to rethink the implementation and ask yourself questions like what can go wrong? how long will this take? why so long? what else can we try? is there any alternative to this solution? These are only a few of the questions that we always ask ourselves.

Check the changelog

Start with a deep analysis of the Rails changelog. Sometimes changes are made to features that your application is not using (like ActionCable, for example). To receive a list of non-compatible gems, change the version of Rails in your Gemfile and try to install them.

With such a list, you can decide which version of those Ruby gems you have to use to enable an upgrade to the new Rails version. Check the changelog for every item on the list. Now, you have a bigger picture of what is coming.

Once you compared the current state of your application with the changes in all Ruby gems that you will upgrade, you can start estimating.

Plan the application configuration

In many cases, the newer version of Rails comes with a different default configuration. For example, some options that used to be turned off in the past can be enabled by default in the next updates. Things like that may lead to various problems if developers are unaware of them.

The easiest way to avoid these kinds of problems, is to ensure that the new configuration is the same as in the old application version. Afterward, you can consider changing the settings one by one, while observing how they affect the application.

Keep in mind the server upgrade

Despite working fine in your local environment, the upgraded application version may cause many problems in staging or production. It happens because server components often need upgrades and the old setup no longer works with the newer version of Rails or related Ruby gems.

Remember about the following connections:

  • Ruby version – upgraded version of Rails may no longer support the version of Ruby used by your application. So while you may have the correct version installed locally, you also need to plan the Ruby version upgrade on the server.
  • Database – your database version may be too old to work with the newer version of Rails. You should plan your production application's database backup, upgrade process, and maintenance time.
  • Related system packages – after upgrading other gems than Rails, you may also need to upgrade system packages to newer versions. It’s often a quick process, but it’s essential to consider it when planning the resources.

Your server type may have a bearing on how long the server upgrade takes. The process should be quick when you host your application on a managed infrastructure like Heroku. But it can take longer if you host your application on a dedicated server where you are responsible for all elements of your infrastructure.

Unit tests are often not enough

In many cases, running the unit tests suite isn't sufficient to detect all issues after an upgrade. Often because the coverage is not great, sometimes because errors are only reproducible by following complex flows.

Increase the change of catching issues by doing the following:

  • Do QA sessions – an experienced quality assurance specialist can spot the issues that the unit tests don’t show. Plan part of the resources to do a few QA sessions in the staging environment where the configuration mirrors the production.
  • Add missing tests – find places in the code where the test coverage is the lowest and secure some time to add missing unit tests. If you practice this with every upgrade, at some point you will reach a very high test coverage. And that will shorten the time needed to upgrade the application to the next version of Rails in the future.
  • Verify your controller and requests tests – ensure that you have the type of tests that go through the whole stack without stubbing the connection to the database or response rendering.

Attention to the test coverage always pays back, especially when upgrading the Rails version in the application. Moreover, having the QA in the team helps ensure that your users won’t experience any issues with the new version of the application.

Good monitoring is a must-have

If you aren't using any error-tracking software, start today, especially if you intend to upgrade your Rails application. Such a tool will help you catch the errors and information required to reproduce them.

Performance measurement software is yet another important part of your server setup. You can use it to pinpoint parts of the application that work slower than before the upgrade. Sometimes, the old code requires changes, as it’s no longer the most efficient way to pull information from a database or other source.

Think about the next upgrade

When you upgrade the Rails application, you collect a lot of information that may be important during the next upgrade, and you might not be aware of that.

  • Deprecation warnings – look for them when you start the server locally, run the tests, or search logs for it. When something is deprecated, most likely, it will be entirely removed in the next version. You can use this information to plan the necessary work for the next upgrade or perform the changes before to smooth out the process.
  • Rubygems upgrades – you won’t be able to use some gems in the next Rails version. If you spot this issue with the current upgrade, you prepare and eliminate those libraries before the upgrade. If you don’t do it, at least you will be aware of what challenges you will face in the near future.

The software upgrade process rarely ends, unless you switch to other technology which no longer maintained. Therefore, always plan the next steps; the process will get quicker with every upgrade.

Update your Rails application to the latest version

If you plan to upgrade your Rails application or you have already started the process, don’t forget about these few essential steps. The upgrade process often seems very difficult, but with the right approach and planning, the road to success is shorter and less problematic for both developers and end-users.

In case you need a hand planning or executing your next upgrade, book a free consultation with our CTO - Paweł Dąbrowski. During the video call, we will talk about your needs, and work out the best solutions to help you smoothly upgrade your app!

Similar articles