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

Railsアップグレード百景

r7kamura
March 22, 2019

 Railsアップグレード百景

2019年3月22日にRails Developers Meetup 2019で登壇した際の発表資料です。

r7kamura

March 22, 2019
Tweet

More Decks by r7kamura

Other Decks in Technology

Transcript

  1. ࡞ۀલʹ΍͓ͬͯ͘ͱྑ͍͜ͱ • GitHub Issuesͷϥϕϧͷ੔ཧ ← ୔ࢁPRΛग़͢ͷͰ • ςετ΍ݕূ؀ڥͷ੔උ ← Կ౓΋σϓϩΠ͢ΔͷͰ

    • ։ൃ؀ڥͷ੔උ ← Կ౓΋ςετΛಈ͔͢ͷͰ • CIͷ੔උ ← Կ౓΋ಈ͔͢͜ͱʹͳΔͷͰ • RuboCopͷ੔උ ← ͍Ζ͍Ζॿ͔ΔͷͰ
  2. CIͷ੔උ • ߴ଎Խ (ྫ: Performance Pricing PlanରԠ) • ςετͷछྨͷݟ௚͠ (ྫ:

    db:migration΋ςετ) • ϩάͷݟ௚͠ (ྫ: ςετதͷෆཁͳඪ४ग़ྗ) • ςετ݁Ռͷू໿ (ྫ: CircleCIͷςεταϚϦʔରԠ)
  3. bundle update • جຊతʹ —conservative ΦϓγϣϯΛ෇͚Δ • bundle update --conservative

    actionmailer actionpack actionview activemodel activerecord activesupport rails railties Έ͍ͨʹ΍Δ • ґଘgemΛઌʹΞοϓάϨʔυ͠ͳ͍ͱ͍͚ͳ͍έʔε΋͋Δ • devise΍rails-i18nΈ͍ͨʹಉ͡όʔδϣϯͰRails 4 & 5྆ରԠ Ͱ͖ͳ͍gem΋͋ΔͷͰ஫ҙ (͜͏͍͏gem͕ຊ౰ʹ໽հ)
  4. rails_kwargs_testing • ςετͰͷϝιουҾ਺͕ get “/”, params: { page: “1” }

    ʹ • RSpecͷϩά͕ܯࠂͰຒΊਚ͘͞Εͯ͠·͏ • 5.0Ҡߦͱಉ࣌ʹೖΕΔͱɺ࡞ۀதʹmasterଆͰςετ͕ॻ ͖׵ΘΔͱconflict͢Δ͠৭ʑେม • 4.2Ͱ΋৽ܗࣜͰॻ͚ΔΑ͏ʹͯ͘͠ΕΔͷ͕͜ͷgem
  5. activerecord-compatible_legacy_migration • class Foo < ActiveRecord::Migration[4.2]; end ͷΑ͏ʹόʔδϣ ϯΛࢦఆ͠ͳ͍ͱ͍͚ͳ͘ͳͬͨ (5.0Ͱܯࠂɺ5.1Ͱྫ֎)

    • 4.2Ͱ͸ActiveRecord::Migration[4.2]ͱ͸ॻ͚ͳ͍ͷͰɺࣄલʹର Ԡ΋Ͱ͖ͣɺόʔδϣϯมߋ࣌ʹ͜ͷରԠ΋ಉ࣌ʹؚ·Εͯ͠·͏ • 4.2Ͱ΋5.xͰ΋ಈ࡞͢ΔܧঝݩΛఏڙͯ͘͠ΕΔͷ͕͜ͷgem • ※·͋Կ΋ରԠͤͣ5.0ʹͯ͠΋db:migration࣌ʹͪΐͬͱܯࠂ͕ ग़ΔΑ͏ʹͳΔ͚͔ͩͩΒɺͦΜͳʹॏཁͰ͸ͳ͍͔΋
  6. Rails 4.2.9ʹͨ͠ΒparamsपΓͰྫ֎͕… • get “/search/:query”, to: “items#search” • Rails 4.2.9ͩͱURIύε͕ASCII-8BITʹͳΔ

    • Rails 4.2.9ͰյΕͯ4.2.10Ͱ௚ͬͨ໰୊ • Railsͷύονόʔδϣϯ͸Ұؾʹ࠷৽·Ͱ্͛Α͏
  7. Rails 5ʹͨ͠ΒINSERTͰྫ֎͕… • `created_on` DATE DEFAULT ‘0’ • Rails 5͔ΒσϑΥϧτͰMySQLαʔόଆͷSQLϞʔυ

    ΋ߟྀ͢ΔΑ͏ʹͳͬͨ • ݁ՌతʹNO_ZERO_DATEͱSTRICT_TRANS_TABLES ͕༗ޮԽ͞ΕͯΤϥʔʹ • Rails 4ͷ಺͔Βݫ͓ͯ͘͘͠͠ͱ٢
  8. Rails 5ʹͨ͠Βىಈ࣌ʹྫ֎͕… • ActiveSupport.on_load(:action_controller) { include Foo } • APIϞʔυ࢖ͬͯͳ͍ͷʹ

    ActionController::API ͕ྫ֎Λ ग़͢Α͏ʹͳͬͨͧ??? • ActiveSupport.on_load(:action_controller) ͸ ActionController::API ͷಡΈࠐΈ࣌ʹ΋ൃՐ͢Δ • Rails 4 ࣌୅ʹ͸૝ఆ͍ͯ͠ͳ͔ͬͨ͜ͱ͕ى͖ͨ
  9. Rails 5ʹͨ͠Β404͕204ʹ… • ςϯϓϨʔτ͕ଘࡏ͠ͳ͍ͱ͖ͷڍಈ͕มΘͬͨ • Rails 4ͩͱྫ֎͕ൃੜͯ͠404 • Rails 5ͩͱ204

    • ͜͜Ͱʮ͍ͭͰʹϦϑΝΫλϦϯάͯ͠͠·͓͏ʯ ͱ͔΍Γ࢝ΊΔͱຊ౰ʹྑ͘ͳ͍…
  10. Rails 5ʹͨ͠ΒControllerͷςετ͕… post “/login”, name: “…”, password: “…” post “/articles”,

    body: “…” • Rails 5.0 ʹROW_POST_DATA͕Ҿ͖ܧ͕ΕΔෆ۩߹͕ • Rails 5.2 Ͱ͸मਖ਼͞Ε͍ͯΔ͕ 5.0 Ͱ͸ͦͷ·· • ద౰ʹΞϓϦଆͰύον౰͙ͯͯ྇ͷ͕ྑͦ͞͏
  11. Rails 5ʹͨ͠ΒparamsपΓͰςετ͕… • get “/foo”, bar: nil, baz: Time.current •

    Rails 4 ·Ͱ͸ςετͰ౉ͨ͠paramsͱͯ͠౉ͨ͠ΦϒδΣΫ τ͕ControllerͰ௚઀ࢀর͞Ε͍ͯͨ • Rails 5͔Β͸ී௨ʹΤϯίʔυ/σίʔυ͞ΕΔ • ຊདྷ͋Γಘͳ͍৚݅ͷςετ͕େྔʹଘࡏ͍ͯͨ͠ • Content-Type΍paramsͷ಺༰Λࡉ͔͘ݟ௚ͯ͠ରԠ͢Δ
  12. Rails 5.1ʹͨ͠ΒparamsपΓͰςετ͕… • get “/”, params: nil ʹͯ͠ΔͱRails 5.1͔Βྫ֎͕ग़Δͧ??? •

    υΩϡϝϯτΛݟΔݶΓparams͸nilͰ΋ྑͦ͞͏ • Ͳ͏΍ΒRails 5.1ʹ͢Δͱ͖ʹ࣮૷ΛϛεͬͨͬΆ͍ • rails/rails#34737 Λग़ͯ͠mergeࡁΈ • Rails 6 ʹ͔͠ೖΒͳ͍ͷͰ 5 Ͱ͸݁ہ nil Λ౉ͤͳ͍
  13. Rails 5.1ʹͨ͠ΒARͷthrough͕… • Rails 5.1͔Β has_many :b, through: a ͕ޮ͔ͳ͍ͧ???

    • ௐࠪͨ͠ΒҰ࿈ͷincludeͷதͰ͜͏͍͏͜ͱ͕ى͖͍ͯͨ X.has_many :a X.has_many :b, through: :a X.has_many :a # ← ͜͜Ͱthrough: :aͷఆ͕ٛফ͑Δ
  14. Tips1: Contributing to Rails͕ศར • rails/rails΁ͷIssueͷग़͠ํ • Pull Requestͷग़͠ํ •

    ςετͷಈ͔͠ํ • ࠷খͷ࠶ݱίʔυΛॻ͘ͱ͖ͷςϯϓϨʔτ