Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails upgrade #m3dev

Rails upgrade #m3dev

How to upgrade Rails version. What I got when upgrading our Rails project from 5.0 to 5.1.0.beta1.
M3 Tech Talk 2017/03/03 #m3dev

Takayuki Matsubara

March 05, 2017
Tweet

More Decks by Takayuki Matsubara

Other Decks in Programming

Transcript

  1. Rails upgrade

    View Slide

  2. self-introduction
    me
    |> name # Takayuki Matsubara
    |> job # Software Engineer Team Leader
    |> work_at # M3, Inc.
    |> works # Elixir, Rails, Java, JavaScript
    |> twitter # ma2ge
    |> github # ma2gedev
    |> oss # PowerAssertEx, breadcrumble,
    # chrono_logger, bundle-star,
    # faraday-encoding

    View Slide

  3. PowerAssertExˑ76
    github.com/ma2gedev/power_assert_ex

    View Slide

  4. Why upgrade?

    View Slide

  5. Why upgrade?
    • Rails do not support old ones. See Also: http://
    guides.rubyonrails.org/maintenance_policy.html
    • To fight the next few years.

    View Slide

  6. Rails upgrade

    View Slide

  7. before we go
    • Read A Guide for Upgrading Ruby on Rails http://
    guides.rubyonrails.org/upgradingrubyon_rails.html
    • Is the test code sufficient?
    • Upgrade to latest version

    View Slide

  8. upgrade steps
    1. ⬜ $ rails app:update
    2. ⬜ $ bundle install
    3. ⬜ fix tests and deprecated features

    View Slide

  9. 1. $ rails app:update
    • executes $ rails app:update
    • protip you can specify THOR_DIFF for checking diff. see
    also: http://qiita.com/ma2ge/items/
    a838864f059fc9b931b2
    • check the difference
    • I recommended to use railsdiff.org. http://railsdiff.org/

    View Slide

  10. upgrade steps
    1. ✅ $ rails app:update
    2. ⬜ $ bundle install
    3. ⬜ fix tests and deprecated features

    View Slide

  11. 2. $ bundle install
    • perhaps it fails first or again and again
    • solve the dependency problems something like the
    following
    • update gems suitable for your new Rails version
    • if there's nothing for suitable version you can make a pull
    request or fork
    • etc...

    View Slide

  12. upgrade steps
    1. ✅ $ rails app:update
    2. ✅ $ bundle install
    3. ⬜ fix tests and deprecated features

    View Slide

  13. 3. fix tests and deprecated features
    • test, test, test
    • fix deprecated features
    • also recommend to modify deprecation warnings

    View Slide

  14. upgrade steps
    1. ✅ $ rails app:update
    2. ✅ $ bundle install
    3. ✅ fix tests and deprecated features

    View Slide

  15. pitfalls on the road to
    Rails 5.1.0.beta1

    View Slide

  16. paranoia gem [1/2]
    • https://github.com/rubysherpas/paranoia
    • caught the error
    fix `ArgumentError: wrong number of arguments (given 3, expected 4)`
    • this bug was fixed on https://github.com/rubysherpas/
    paranoia/pull/384

    View Slide

  17. paranoia gem [2/2]
    -gem 'paranoia'
    +gem 'paranoia', github: "rubysherpas/paranoia", branch: "core" # TODO:

    View Slide

  18. Cannot add foreign key constraint [1/4]
    • caught the error
    CREATE TABLE `xxx` (`id` bigint NOT NULL AUTO_INCREMENT PRIMARY KEY, \
    `yyy_id` bigint, `name` varchar(255), INDEX `index_xxx_on_yyy_id` \
    (`yyy_id`), CONSTRAINT `fk_rails_be560b73e9`
    -> FOREIGN KEY (`yyy_id`)
    -> REFERENCES `yyy` (`id`)
    -> ) ENGINE=InnoDB;
    ERROR 1215 (HY000): Cannot add foreign key constraint

    View Slide

  19. Cannot add foreign key constraint [2/4]
    • Change Default Primary Keys to BIGINT #26266 https://
    github.com/rails/rails/pull/26266

    View Slide

  20. Cannot add foreign key constraint [3/4]
    class CreateXxx < ActiveRecord::Migration[5.1]
    def change
    create_table :xxx do |t|
    t.references :yyy, foreign_key: true
    t.string :name
    end
    end
    end

    View Slide

  21. Cannot add foreign key constraint [4/4]
    # plan 1
    +class CreateXxx < ActiveRecord::Migration[5.0]
    -class CreateXxx < ActiveRecord::Migration[5.1]
    # plan 2
    + t.references :yyy, foreign_key: true
    - t.references :yyy, type: :integer, foreign_key: true
    # plan 3
    change all old migration to 5.1 if you are developing new project

    View Slide

  22. Let's upgrade !

    View Slide