Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Railsアップグレード百景
Search
r7kamura
March 22, 2019
Technology
11
6.5k
Railsアップグレード百景
2019年3月22日にRails Developers Meetup 2019で登壇した際の発表資料です。
r7kamura
March 22, 2019
Tweet
Share
More Decks by r7kamura
See All by r7kamura
個人開発のやっていき方
r7kamura
94
23k
amakanにおける書籍のシリーズ判定方法について 2016-08-21
r7kamura
10
6k
Tenkaichi Bot Butoukai
r7kamura
11
5.1k
Paging in API
r7kamura
3
8.6k
Chanko Hacking Guide
r7kamura
5
1.2k
Making things with something small
r7kamura
1
460
Hidden
r7kamura
0
73
Butsukari Geiko
r7kamura
10
36k
Casual CI Server
r7kamura
7
1.8k
Other Decks in Technology
See All in Technology
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
31k
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
420
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
510
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
260
祝!Iceberg祭開幕!re:Invent 2024データレイク関連アップデート10分総ざらい
kniino
2
240
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
150
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
210
Wantedly での Datadog 活用事例
bgpat
1
410
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
180
KubeCon NA 2024 Recap / Running WebAssembly (Wasm) Workloads Side-by-Side with Container Workloads
z63d
1
240
OpenAIの蒸留機能(Model Distillation)を使用して運用中のLLMのコストを削減する取り組み
pharma_x_tech
4
540
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
Making Projects Easy
brettharned
116
5.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Optimizing for Happiness
mojombo
376
70k
The Cult of Friendly URLs
andyhume
78
6.1k
Agile that works and the tools we love
rasmusluckow
328
21k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Transcript
RailsΞοϓάϨʔυඦܠ by r7kamura
ࣗݾհ • Ryo Nakamura • https://github.com/r7kamura • https://twitter.com/r7kamura • ϑϦʔϥϯεͰRailsͷࣄΛ͍ͬͯ·͢
• Rails 1͔Β6·ͰΞοϓάϨʔυͨ͜͠ͱ͋Γ
ࠓ͢͜ͱ ʮRailsͬͯ͜͏͍͏ײ͡ͰΞοϓάϨʔυ͍ͯ͘͠ͱ ྑ͍ͷͶʯͱ͍͏ͷ͕͔ͬͯΒ͑Δͱخ͍͠ • ࣄલ४උ • ΞοϓάϨʔυͷྲྀΕ (Rails 4, 5,
6͕ର) • ࣄྫू
ࠓ͞ͳ͍͜ͱ • Πϯϑϥͷ (1͚ͩΞοϓάϨʔυ͢ΔɺϦΫΤετΛෳ ͯ͠ݕূڥʹྲྀ͢) • ৫ίϛϡχέʔγϣϯͷ (ۀҕୗͰ୲͢Δ߹ͷ͋ Ε͜ΕɺϨϏϡΞʔׂͷ͋Ε͜Ε) •
QAख๏ͷ (ςετ߲ͷબఆํ๏ͳͲ) • ݩʑΞοϓάϨʔυͷ·ΓͲ͜Ζ100બʹ͢Δ༧ఆͩͬͨ
ࣄલ४උ
࡞ۀલʹ͓ͬͯ͘ͱྑ͍͜ͱ • GitHub Issuesͷϥϕϧͷཧ ← ࢁPRΛग़͢ͷͰ • ςετݕূڥͷඋ ← ԿσϓϩΠ͢ΔͷͰ
• ։ൃڥͷඋ ← ԿςετΛಈ͔͢ͷͰ • CIͷඋ ← Կಈ͔͢͜ͱʹͳΔͷͰ • RuboCopͷඋ ← ͍Ζ͍Ζॿ͔ΔͷͰ
GitHub Issuesͷϥϕϧͷཧ
ςετݕূڥͷඋ • RailsΞοϓάϨʔυ࣌ʹͦ͜ςετͷ͋Γ͕ͨ͞Λ ௧ײ͢Δ͜ͱʹͳΔ… • Pull Request͝ͱʹݕূڥ͕༻ҙ͞ΕΔ͕ͭ͋Δ ͱຊʹศར • μϛʔσʔλ͕༻ҙ͞Ε͍ͯΔݕূڥͩͱϕετ
ʢ2ͭҎ্Ϩίʔυ͕͋Δͱࣦഊ͢Δͱ͔͋Δʣ
CIͷඋ • ߴԽ (ྫ: Performance Pricing PlanରԠ) • ςετͷछྨͷݟ͠ (ྫ:
db:migrationςετ) • ϩάͷݟ͠ (ྫ: ςετதͷෆཁͳඪ४ग़ྗ) • ςετ݁Ռͷू (ྫ: CircleCIͷςεταϚϦʔରԠ)
None
None
RuboCopͷඋ • Bundler/Gemfileʹै͓ͬͯ͘ͱޙͷมߋ࡞ۀָ͕ • RailsΧςΰϦͷCop༗ޮԽ͓ͯ͘͠ͱḿΔ • ηΩϡϦςΟύϑΥʔϚϯεͷݟͯ͘ΕΔ • ݹ͍APIͷݺͼग़͠Λauto-correctͰ͖Δͷศར
GemfileͰͷఆٛॱংͷ᠘ • গͳ͘ͱrailsઌ಄ʹॻ͍͓͍ͯͨํ͕ྑ͍ • ͜͏͍͏ίʔυؚ͕·ΕΔGem͕͋ΔͨΊ if defined?(Rails) … end
ΞοϓάϨʔυͷྲྀΕ
ΞοϓάϨʔυͷྲྀΕ 1. bundle update 2. ςετͱमਖ਼ 3. masterͷऔΓࠐΈ (ਵ࣌σϓϩΠ) 4.
όʔδϣϯมߋΛσϓϩΠ 5. ࣄޙॲཧ
bundle update • جຊతʹ —conservative ΦϓγϣϯΛ͚Δ • bundle update --conservative
actionmailer actionpack actionview activemodel activerecord activesupport rails railties Έ͍ͨʹΔ • ґଘgemΛઌʹΞοϓάϨʔυ͠ͳ͍ͱ͍͚ͳ͍έʔε͋Δ • deviserails-i18nΈ͍ͨʹಉ͡όʔδϣϯͰRails 4 & 5྆ରԠ Ͱ͖ͳ͍gem͋ΔͷͰҙ (͜͏͍͏gem͕ຊʹհ)
None
ςετͱमਖ਼ 1. ςετ͕ਖ਼ৗʹ࣮ߦ͞ΕΔΑ͏ʹ͢Δ 2. ςετͷࣦഊΛ0݅ʹ͢Δ 3. ܯࠂͷΛݮΒ͍ͯ͘͠ 4. masterʹมߋ͕͋ΕऔΓࠐΜͰ1ʹΔ
ςετҎ֎Ͱ͓͢͢Ίͷ֬ೝࣄ߲ • rails console ͕ਖ਼ৗʹىಈ͢Δ͔? • RubyCSSͷϑΝΠϧΛฤूͨ͠ͱ͖ө͞ΕΔ͔? • Rails.application.eager_load! ͕ޭ͢Δ͔?
• rails db:rollback db:migration ͕ޭ͢Δ͔? • RAILE_ENV=production rails assets:precompile ͕ޭ͢Δ͔?
None
None
masterͷऔΓࠐΈ • Ұʹࢁมߋ͢ΔͱݕূrevertେมͳͷͰɺ όʔδϣϯมߋ࣌ͷࠩ࠷খԽ͍ͨ͠ • มߋ৽چόʔδϣϯ྆ରԠͳܗͰՃ͑Δ • ςετͷमਖ਼ͱฒߦͯ͠masterʹมߋΛೖΕ͍ͯ͘ (ͷͰ༧Ίcommit͚͓ͯ͜͏)
ࠩΛখ͘͢͞Δ • bundle update ͷ —conservative Φϓγϣϯ • rails_kwargs_testing •
activerecord-compatible_legacy_migration
rails_kwargs_testing • ςετͰͷϝιουҾ͕ get “/”, params: { page: “1” }
ʹ • RSpecͷϩά͕ܯࠂͰຒΊਚ͘͞Εͯ͠·͏ • 5.0Ҡߦͱಉ࣌ʹೖΕΔͱɺ࡞ۀதʹmasterଆͰςετ͕ॻ ͖ΘΔͱconflict͢Δ͠৭ʑେม • 4.2Ͱ৽ܗࣜͰॻ͚ΔΑ͏ʹͯ͘͠ΕΔͷ͕͜ͷgem
Rails/HttpPositionalArguments • લड़ͷϝιουҾΛݕࠪ͢ΔCop • લճrails5-spec-converterΛ͕ͬͨbuggy… • CopͰauto-correct͢Δͷ͕ྑͦ͞͏
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࣌ʹͪΐͬͱܯࠂ͕ ग़ΔΑ͏ʹͳΔ͚͔ͩͩΒɺͦΜͳʹॏཁͰͳ͍͔
ࣄྫू
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ͷύονόʔδϣϯҰؾʹ࠷৽·Ͱ্͛Α͏
Rails 5ʹͨ͠ΒINSERTͰྫ֎͕… • `created_on` DATE DEFAULT ‘0’ • Rails 5͔ΒσϑΥϧτͰMySQLαʔόଆͷSQLϞʔυ
ߟྀ͢ΔΑ͏ʹͳͬͨ • ݁ՌతʹNO_ZERO_DATEͱSTRICT_TRANS_TABLES ͕༗ޮԽ͞ΕͯΤϥʔʹ • Rails 4ͷ͔Βݫ͓ͯ͘͘͠͠ͱ٢
Rails 5ʹͨ͠Βىಈ࣌ʹྫ֎͕… • ActiveSupport.on_load(:action_controller) { include Foo } • APIϞʔυͬͯͳ͍ͷʹ
ActionController::API ͕ྫ֎Λ ग़͢Α͏ʹͳͬͨͧ??? • ActiveSupport.on_load(:action_controller) ActionController::API ͷಡΈࠐΈ࣌ʹൃՐ͢Δ • Rails 4 ࣌ʹఆ͍ͯ͠ͳ͔ͬͨ͜ͱ͕ى͖ͨ
Rails 5ʹͨ͠Β404͕204ʹ… • ςϯϓϨʔτ͕ଘࡏ͠ͳ͍ͱ͖ͷڍಈ͕มΘͬͨ • Rails 4ͩͱྫ֎͕ൃੜͯ͠404 • Rails 5ͩͱ204
• ͜͜Ͱʮ͍ͭͰʹϦϑΝΫλϦϯάͯ͠͠·͓͏ʯ ͱ͔Γ࢝ΊΔͱຊʹྑ͘ͳ͍…
Rails 5ʹͨ͠ΒControllerͷςετ͕… post “/login”, name: “…”, password: “…” post “/articles”,
body: “…” • Rails 5.0 ʹROW_POST_DATA͕Ҿ͖ܧ͕ΕΔෆ۩߹͕ • Rails 5.2 Ͱमਖ਼͞Ε͍ͯΔ͕ 5.0 Ͱͦͷ·· • దʹΞϓϦଆͰύον͙ͯͯ྇ͷ͕ྑͦ͞͏
Rails 5ʹͨ͠ΒparamsपΓͰςετ͕… • get “/foo”, bar: nil, baz: Time.current •
Rails 4 ·ͰςετͰͨ͠paramsͱͯͨ͠͠ΦϒδΣΫ τ͕ControllerͰࢀর͞Ε͍ͯͨ • Rails 5͔Βී௨ʹΤϯίʔυ/σίʔυ͞ΕΔ • ຊདྷ͋Γಘͳ͍݅ͷςετ͕େྔʹଘࡏ͍ͯͨ͠ • Content-Typeparamsͷ༰Λࡉ͔͘ݟͯ͠ରԠ͢Δ
Rails 5ʹͨ͠ΒparamsपΓͰྫ֎͕… • ActionController::Parameters͕HashΛܧঝ͠ͳ͘ͳͬͨ (େม͗͢Δ) • ҰԠ5.0Ͱܯࠂ͖ͰHash૬ͷϝιου͕ݺͼग़ͤΔ Α͏ʹߟྀ͞Ε͍ͯΔ • ͔͠͠
params.is_a?(Hash) ʹഊ • ͜ͷܧঝݩมߋͷӨڹ͕Rails 5ԽͰҰ൪ා͍
Rails 5.1ʹͨ͠ΒparamsपΓͰςετ͕… • get “/”, params: nil ʹͯ͠ΔͱRails 5.1͔Βྫ֎͕ग़Δͧ??? •
υΩϡϝϯτΛݟΔݶΓparamsnilͰྑͦ͞͏ • Ͳ͏ΒRails 5.1ʹ͢Δͱ͖ʹ࣮ΛϛεͬͨͬΆ͍ • rails/rails#34737 Λग़ͯ͠mergeࡁΈ • Rails 6 ʹ͔͠ೖΒͳ͍ͷͰ 5 Ͱ݁ہ nil Λͤͳ͍
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ͷఆ͕ٛফ͑Δ
Rails 6ʹͨ͠Βvalidation͕… • Rails 6͔Βhas-and-belongs-to-manyͳதؒϨίʔυͰ ఆ͍ٛͯ͠Δvalidation͕ಈ͔ͳ͘ͳͬͨ…? • ࠶ݱίʔυॻ͍ͯTwitterͰΰωͯͨΒkamipo͞Μ͕ rails/rails#35116 Ͱͯ͘͠Εͨ
• ͜ͷޙผ݅Ͱ࠶ݱίʔυॻ͍ͯ2ʙ3ճΰωͯͨΒ kamipo͞Μ͕શ෦ͯ͘͠Εͨ…
Rails 6ʹͨ͠Βbelongs_toͷڍಈ͕… • ಉ͡Ϋϥε͔Βಉ͡Ϋϥεʹbelongs_toΛผ໊Ͱఆ ͍ٛͯ͠ΔϞσϧͰɺinverse_of͕ڞ༻͞Εͯ͠·͏ • ࠶ݱՄೳ͕ͩະղܾ • rails/rails#35204 ͰIssueΛཱͯͯௐࠪத
Tips1: Contributing to Rails͕ศར • rails/railsͷIssueͷग़͠ํ • Pull Requestͷग़͠ํ •
ςετͷಈ͔͠ํ • ࠷খͷ࠶ݱίʔυΛॻ͘ͱ͖ͷςϯϓϨʔτ
Tips2: r7kamuraʹؙ͛͢Δબࢶ • ࣮ࡍRailsΞοϓάϨʔυΛ୭͕୲͢Δͷ͔ʁ • ਓࣄධՁݸʑਓͷϞνϕʔγϣϯͷ͕͋Δ • ୲ऀΛ͚ͯۀҕୗͷਓʹؙ͛͢Δͱ͍͏ͷ ৭ʑߟ͑ΔͱΘΓͱ༗ޮͩͱࢥ͍ͬͯΔ •
RailsΞοϓάϨʔυͷࣄΛืू͍ͯ͠·͢
͓͞Β͍
͓͞Β͍ • ࡞ۀͱฒߦͯ͠։ൃج൫Λ͍͑ͯ͜͏ • ύονόʔδϣϯҰؾʹ্͛Α͏ • όʔδϣϯมߋ࣌ͷࠩΛ࠷খԽ͍ͯ͜͠͏ • ᠘ଟ͍͕ਅ໘ʹςετॻ͍ͯͨΒݕͰ͖Δ •
Railsଆ͕͓͔͍͠ͳͱࢥͬͨΒ࠶ݱίʔυΛॻ͜͏