“Coding is easy. Setup and maintenance are hard.” – Lots of coders everywhere

I’ve got an old app that’s not too complicated that my old anesthesia department has used daily for over 10 years, It’s currently using Rails 6.1.6 and ruby 2.7.2 that Heroku will no longer let me update starting this coming May 1, 2025. So, time to upgrade. I’ve gone through this process twice before. I’ve tried twice on my own before getting hopelessly stuck and having to call in the cavalry, a real coder named Mykl Clason. (It’s pronounced like “Michael.” You can thank his mom for the spelling who knew that it would build character.) He’s very skilled and patient and rescued me both times. This time I’m taking a break from full time work so might have more time and energy to focus on the upgrade. Fingers crossed.

Best Practices

The Rails Guides provides some guidance on Upgrading Ruby on Rails. They suggest several things: don’t upgrade unless you really need to, great test coverage on the original app and then upgrading slowly, ruby first, and then rails, latest patch version of current version and then to the next version. You fix deprecation warnings and failed tests as you go.

That’s excellent advice. But truth be told, I couldn’t keep up with test coverage long ago. For starters, the tests started to take too long to run on my computer. Then I had different code that needed to be run on different days of the week. I’m sure there’s a way but managing and keeping track of time in my test environment and other details broke me back then. Maybe I can make testing work in rails 8.0.1… ? Maybe? I’m going to try.

My Upgrade Approach

My approach will be somewhat different taking into account the relative lack of complexity of my app (I hope) and my time. Here’s my basic outline:

  • Backup and Upgrade the Database
    Use heroku pg:copy to create a duplicate of the legacy database. This will also upgrade it to the latest PostgreSQL version on Heroku, leaving the original database untouched.

  • Download the Updated Database
    Capture a backup of the upgraded database and download it locally for development.

  • Set Up PostgreSQL Locally
    Install and configure PostgreSQL on my local machine, then restore the downloaded backup using pg_restore.

  • Create a Rails 8 App
    Generate a new Rails 8.0.1 app with Ruby 3.3.7 and configure it to connect to the restored local database.

  • Rebuild the User Model
    Recreate the user model in the new app, excluding outdated authentication fields while preserving other attributes.

  • Test Local Database Access
    Verify that the app can interact with the legacy database by running simple queries like User.first through the Rails console.

  • Deploy to Heroku
    Push the Rails 8 app to Heroku and connect it to the duplicated, upgraded database.

  • Expand Models
    Recreate the remaining models and ensure proper database interactions both locally and on Heroku.

  • Implement Testing
    Start with basic model tests, introduce validations, and progressively build test coverage for the application.

  • Recreate the App
    Use test-driven development (TDD) to rebuild the application step by step, ensuring reliability and scalability.

As I reflect now, it wouldn’t be the worst thing to do to try to upgrade this app as is to later ruby versions and then rails versions. If I get stuck, I may explore upgrading the existing app incrementally to Rails 7.2 or adding testing coverage to the original app.

This is my initial overall approach but I will document more specific steps and details as I go along in future posts.

“False starts are starts. So just start.” – Ben Unger

You don’t really understand the problem space until you start confronting it.

Yes, I will consult with ChatGPT

ChatGPT does have great insights into a lot of the problems I face. But you’ve got to keep an eye on it. It often makes mistakes and gets confused. We’ll see how useful it is for me with this project.

Online Resources for Testing and Upgrading

I’m definitely sympathetic to TDD for creating robust programs but for now I figure that I should apply that to a new Rails 8 app and give a new app longer life on Heroku. You can check out the Rails Testing Guide.

There’s a great article by Rémi Mercier about upgrading from Rails 5.2 to Rails 6.0 with details about deprecation warnings, the rails app:update command, reading changelogs, etc. It serves as a cautionary tale about how upgrades can quickly become overwhelming without proper planning and careful incremental work. I didn’t even know what a linter was that he referred to. (For those of you who, like me, didn’t know what a linter is, it’s a tool that checks your code for style issues and potential bugs, which can be incredibly helpful during an upgrade.)

Let me hear from you.

I haven’t added comments yet, but if you’d like to share your thoughts or experiences, feel free to email me. Have you tackled a Rails upgrade or a similar challenge? I’d love to hear your insights. If I hear from someone, I’ll add a comment section to make discussions easier.