Upgrade rails from 5.1 to 5.2
Upgrading application rails version from 5.1
to 5.2
is much easier than doing from 4.2 to 5.0 or from 5.0 to 5.1, there are very few changes to handle and chances are there is no test failure.
Things to handle
- Add
bootsnap
toGemfile
Rails 5.2 uses a gem calledbootsnap
to speed up app boot time, when you runrails app:update
, theboot.rb
will be updated to have such line:
require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
However, when you run rails c
or rails s
, chances are an error will be thrown about the missing of the bootsnap
gem in Gemfile
, which is due to that the upgraded version of app does not have the gem included in Gemfile yet. Just add it as follows:
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
- Config defaults
Rails 5.2 introduces a bunch of default configurations which are saved in theconfig/initializers/new_framework_defaults_5_2.rb
file and by default commented out.
It depends on the use cases per specific app to decide whether it is necessary to use the defaults, when in doubt, you can just keep the defaults from previous version and only enable the new config that's necessary. For instance:
config.load_defaults 5.1
and uncomment out any config that is really necessary in the new_framework_defaults_5_2.rb
file.
Others
- Rails 5.2 removed
limit: 24
option forfloat
type, so you need regenerate a copy ofschema.rb
under rails 5.2 by:
$ bin/rails db:schema:dump
- Deprecation warning about
dalli_store
, which can be replaced with official:mem_cache_store
. You can follow the official documentation for the switch when necessary:
DEPRECATION: :dalli_store will be removed in Dalli 3.0.
Please use Rails' official :mem_cache_store instead.
https://guides.rubyonrails.org/caching_with_rails.html
Summary
Based on app features, there might be other things to handle, such as the use of config/credentials.yml.enc
and config/master.key
and so on.
For more detailed changes, always refer to the offical upgrade guide and release notes: