Update Rails version rails 5.2.3 to 7.1.3

Hi everyone, I’ve been working with Rails for over a year now. The project I’m working on needs to be updated to new versions of Rails.

The project is blued with ruby ​​​​​​​​​​​​​​​​​version 2.7.2 and rails 5.2.3 and other dependencies that may have been updated or discontinued, currently not tested and the only documentation is only about user registration.

I’m researching best practices for upgrading Rails, perhaps to version 7. And I appreciate any help.

This is my GemFile

source ‘https://rubygems.org

git_source(:github) { |repo| “GitHub · Build and ship software on a single, collaborative platform · GitHub” }

ruby ‘2.7.2’

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'

gem ‘rails’, ‘~> 5.2.3’

# Use postgresql as the database for Active Record

gem ‘pg’, ‘>= 0.18’, ‘< 2.0’

# Use Puma as the app server

gem ‘puma’, ‘~> 3.11’

# Use SCSS for stylesheets

gem ‘sass-rails’, ‘~> 5.0’

# Use Uglifier as compressor for JavaScript assets

gem ‘uglifier’, ‘>= 1.3.0’

gem ‘sidekiq’, ‘< 7’

gem “aws-sdk-sqs”

gem ‘nio4r’, ‘~> 2.5’

gem ‘rake’, ‘~> 13.2.1’

gem ‘rack-cors’#, require: ‘rack/cors’

gem ‘jwt’

# Conversao valores formato moeda para busca

gem ‘money’

gem ‘faraday’

gem ‘json’

gem ‘ffi’, ‘<= 1.15.5’

# net/protocol

gem “net-http”

# Use CoffeeScript for .coffee assets and views

gem ‘coffee-rails’, ‘~> 4.2’

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder

gem ‘jbuilder’, ‘~> 2.5’

gem ‘aws-sdk’

gem “httparty”

gem “will_paginate”

gem ‘bootstrap-generators’, ‘~> 3.3.4’

gem ‘activerecord-session_store’

# Exportação de dados para o Excel

gem ‘write_xlsx’

gem “recaptcha”

# Create beautiful JavaScript charts with one line of Ruby

gem ‘chartkick’

gem ‘groupdate’

# Use Redis adapter to run Action Cable in production

gem ‘redis’, ‘4.8.1’

# Reduces boot times through caching; required in config/boot.rb

gem ‘bootsnap’, ‘>= 1.1.0’, require: false

group :development, :test do

gem ‘rspec-rails’

gem ‘shoulda-matchers’

gem ‘byebug’, platforms: [:mri, :mingw, :x64_mingw]

gem ‘rb-readline’

end

group :development do

# Access an interactive console on exception pages or by calling 'console' anywhere in the code.

gem ‘web-console’, ‘>= 3.3.0’

gem ‘listen’, ‘>= 3.0.5’, ‘< 3.2’


# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring

gem ‘spring’

gem ‘spring-watcher-listen’, ‘~> 2.0.0’

end

group :test do

# Adds support for Capybara system testing and selenium driver

gem ‘capybara’, ‘>= 2.15’

gem ‘selenium-webdriver’

# Easy installation and use of chromedriver to run system tests with Chrome

gem ‘chromedriver-helper’

end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem

gem ‘tzinfo-data’, platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem ‘bootstrap’, ‘~> 4.3.1’, require: false

gem ‘bootstrap-sass’

gem ‘jquery-rails’

gem ‘rest-client’

gem ‘savon’, ‘~> 2.12.0’

gem ‘simple_form’

gem ‘popper_js’

gem ‘tether-rails’

I’m in the same boat; going from 6.1 - 8.

This is my strategy

  • Depend on the test suite to check for regression through upgrades
  • Upgrade the Ruby to the desired version first, before upgrading Rails
  • While upgrading — Ruby or Rails
    • Upgrade to the latest minor version first, before crossing between major versions
    • Implement “benefits” before upgrading away from that version — else it’s never going to get updated — this includes updating the gems as well.

Tech Debt is a finicky thing

Good luck!!

Thanks for the help…

A word of caution: While upgrading a Rails app from 5.2 to 7.2, I did upgrade Ruby first, only to discover that some gems are not compatible with 3.x. This page has handy a chart showing which Ruby versions are compatible with each version of Rails.

And of course you’ll need to check each third party gem for Ruby version compatibility.

1 Like

If you intend to keep this app running and developable for some time into the future, I suggest to aim for the latest version of Rails and Ruby with your upgrade project – don’t plan to stop at Rails 7. Once it is at the latest version, if economically possible, set aside a few hours a month to keep the app and its dependencies up to date. It’s less stressful to continuously do small updates than do a large update at once.

There are different strategies to get there, but for all of them at least a rudimentary test coverage helps a lot. Can you put in some effort in the beginning to write some system tests? Start as simple as possible – maybe a test that visits the root page and expects some text on it? (Hard enough if there is no setup for system tests yet.)

The common strategy to upgrade Rails is to go up one step for each minor version. So from 5.2 to 6.0, from 6.0. to 6.1, from 6.1 to 7.0 and so on. For each step, follow the general upgrade process as documented in Upgrading Ruby on Rails — Ruby on Rails Guides, and the step-specific instructions there (e.g. 5.2 to 6.0). Upgrade gem dependencies and Ruby with each step as far as necessary.

Another strategy is to port the app to the newest version by copying and adapting the relevant business logic and view code over to a fresh new Rails app. Find a way how both the old and the new app can access the same production database, and run both in parallel. This way, the app can be ported piece by piece and verified in small chunks. Getting there might require some hacks – I’ve seen a good blog post about this somewhere but can’t find it right now.

Both strategies have their pros and cons. Usually going step by step is safer, but since there are many steps between 5.2 and 8.0, the other strategy might be worth a consideration.

The most critical aspect of the upgrade is often the frontend code. E.g. your app is using sass, which is less needed with modern CSS and less used in Rails nowadays. Is your app depending a lot of it, or could you get rid of it? Do you need a node based bundler, or could you use importmaps? Do you need any javascript or CSS postprocessing at all?

1 Like

At the moment the project is a monolith, we are migrating to microservices, separating the bankend from the frontend, and creating APIs that communicate with external partners. Our system is a sales center for electronic recharges, telephone recharges, satellite TV plan top-ups, BETS sales, NETFLIX plans, among others.

I want to have the entire business model focused solely on Rails and small subsystems (APIs) that will have the function of communicating with external partners via VPN. So far we have migrated 70% of the frontend to separate services, the main objective is to transform the monolith into an API, which serves the frontend and depends on other APIs to be able to make sales.

This is my migration plan, since we only have the source code as a point of reference and documentation.

  • Identify ruby ​​version X compatible with realis version Y

  • Identify next version for realis update

  • List enhancement updates between different versions

  • Update all GEMS

  • Update RAILS

  • Update RUBY

  • Creating Tests

  • Creating Documentation