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
rubyhiroba
Search
Ryoichi SEKIGUCHI
September 21, 2014
Technology
6
1.2k
rubyhiroba
Ryoichi SEKIGUCHI
September 21, 2014
Tweet
Share
More Decks by Ryoichi SEKIGUCHI
See All by Ryoichi SEKIGUCHI
Ruby makes everything
ryopeko
0
92
正しく失敗しながら進むプロダクト開発/railsdm2018
ryopeko
10
5.8k
CircleCI を使って自動(ほぼ)でセキュリティアップデート / circleci meetup
ryopeko
4
490
Kaizen Platform でやっている Kaizen Week というイベントについて / kaize week tokyurubykaigi 10
ryopeko
2
1.1k
mysql casual talks vol7
ryopeko
0
2.3k
devsumi2014-dena-bootcamp2014
ryopeko
40
63k
jtrk02
ryopeko
0
5.5k
DeNA Bootcamp 2013
ryopeko
15
7.4k
自分の道具を知る
ryopeko
10
2.1k
Other Decks in Technology
See All in Technology
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
210
Terraform未経験の御様に対してどの ように導⼊を進めていったか
tkikuchi
2
430
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
150
複雑なState管理からの脱却
sansantech
PRO
1
130
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
0
110
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
TypeScript、上達の瞬間
sadnessojisan
46
13k
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
[FOSS4G 2019 Niigata] AIによる効率的危険斜面抽出システムの開発について
nssv
0
310
Platform Engineering for Software Developers and Architects
syntasso
1
510
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
220
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
860
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Unsuck your backbone
ammeep
668
57k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
A designer walks into a library…
pauljervisheath
203
24k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
How to train your dragon (web standard)
notwaldorf
88
5.7k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Transcript
Rails ʹ͓͚Δ ֎෦γεςϜͱͷεϜʔζͳ ౷߹։ൃ ؔޱ྄Ұ ! ryopeko " ryopeko 3VCZ)JSPCBੜ׆ൃදձ
ؔޱ ྄Ұ # ryopeko " ryopeko • ύʔϑΣΫτRuby ڞஶऀ •
σϒαϛ2014εϐʔΧʔ • ϕετεϐʔΧʔ 2Ґड • ࠷ۙਓ͔ؒͨͪΒෳDBͱݺ Ε͍ͯΔ
IUUQBENJOTCBS
֎෦γεςϜΛͬͨ ৽ΞϓϦέʔγϣϯ։ൃ
IUUQEJBSZTIVDSFBNOFUCMPHSVCZLBJHJMJHIUOJOHUBMLTIUNM lΈΜͳͬͱಠࣗݚڀͷՌΛൃද͢Δͱ͍͍ͱࢥ͏
֎෦γεςϜͱͷܨ͗͜Έ $ API % RPC DB ࢀর
ࠓճDBΛڞ༗͢Δ߹ͷ ख๏ʹ͍ͭͯͷ͓
' "QQ
' "QQ ' "QQ
' "QQ ' "QQ ' "QQ
' "QQ ' "QQ ' "QQ
DBڞ༗ͨ͠߹ʹ ʹͳͬͯ͘Δ͜ͱ
ෳਓͰ։ൃ͍ͯ͠Δ߹ BQQMF DIFSSZ QFBDI HSBQF PSBOHF GSVJUT
ෳਓͰ։ൃ͍ͯ͠Δ߹ BQQMF DIFSSZ QFBDI HSBQF PSBOHF GSVJUT TFMFDU
ෳਓͰ։ൃ͍ͯ͠Δ߹ BQQMF DIFSSZ QFBDI HSBQF PSBOHF GSVJUT TFMFDU TFMFDU
ෳਓͰ։ൃ͍ͯ͠Δ߹ BQQMF DIFSSZ QFBDI HSBQF PSBOHF GSVJUT TFMFDU EFMFUF TFMFDU
ෳਓͰ։ൃ͍ͯ͠Δ߹ BQQMF DIFSSZ QFBDI HSBQF PSBOHF GSVJUT TFMFDU EFMFUF TFMFDU
Unit Test Ͱಉ༷
Unit Test ࣌ͷڞ༗DBͷࠔΓࣄ • ςετ༻ͷDB͕ڞ༗͞ΕͯΔͱ݁ՌʹӨڹ • ςετ༻ͷDB͕ଘࡏ͠ͳ͍߹DBͷϦΫ ΤετΛϞοΫ͢Δඞཁ • ςετσʔλΛ༻ҙ͢Δͷ͕͘͠ͳΔ
ڞ༗DBͷεΩʔϚมߋʹ ै͢Δͷ͕େม
͜͜·ͰͰ σϝϦοτΛ·ͱΊΔͱ…
DBڞ༗ͨ͠߹ͷσϝϦοτ • ෳਓͰͷ։ൃ࣌ʹσʔλෆ߹ͱͳΔ • Unit Test ࣌ʹڞ༗DBͷऔΓѻ͍͕ࡶʹͳΔ • ڞ༗DBͷεΩʔϚมߋʹै͢Δͷ͕େม
ΓखݩʹDB͕͋ͬͯ΄͍͠… (Rails ͬͯखݩʹDB࡞Γ·͢͠…)
Ͱखݩʹ ࣋ͬͯΈ·͠ΐ͏
DBڞ༗ͨ͠߹ͷσϝϦοτ • ෳਓͰͷ։ൃ࣌ʹσʔλෆ߹ͱͳΔ • Unit Test ࣌ʹڞ༗DBͷऔΓѻ͍͕ࡶʹͳΔ • ڞ༗DBͷεΩʔϚมߋʹै͢Δͷ͕େม ্ͭղܾͦ͠͏ʜ
खݩʹ࣋ͭ߹ͷ σϝϦοτʹ͍ͭͯߟ͑ͯΈΔ
खݩʹDBΛ࣋ͬͨ߹ͷσϝϦοτ • σʔλͷ४උ͕େม • ରʹ Slave ؚ͕·Ε͍ͯͯߋ৽ܥ SQL ଧͭΑ͏ͳ ίʔυΛॻ͍͍ͯΔ߹ɺຊ൪ͰϨϓϦ͕ࢭ·ͬͯ
ࢮ͵ • ݩͷDBεΩʔϚΛΔज़͕ඞཁ • ݩͷDBεΩʔϚΛखݩʹ؆୯ʹ࠶ݱ͢Δज़͕ඞཁ
σʔλͷ४උ͕େม
σʔλͷ४උ͕େม • db:seed తͳΈͰҰׅͰ༻ҙ͢Δ • ֎෦͔Βࢀর͢ΔͷΈͷDBͷ߹ɺσʔλύ λʔϯΛཏͰ͖Δͱ͍͏ϝϦοτ • େมͳͷύλʔϯͷϝϯς •
(Ͳ͏ͤςετͰඞཁͩ͠)
खݩʹDBΛ࣋ͬͨ߹ͷσϝϦοτ • σʔλͷ४උ͕େม • ରʹ Slave ؚ͕·Ε͍ͯͯߋ৽ܥ SQL ଧͭΑ͏ͳ ίʔυΛॻ͍͍ͯΔ߹ɺຊ൪ͰϨϓϦ͕ࢭ·ͬͯࢮ
͵ • ݩͷDBεΩʔϚΛΔज़͕ඞཁ • ݩͷDBεΩʔϚΛखݩʹ؆୯ʹ࠶ݱ͢Δज़͕ඞཁ
Slave ʹߋ৽ܥΫΤϦ
Slave ʹߋ৽ܥΫΤϦ • # eagletmt/switch_point Λ͏͜ͱͰղܾ • Slave ʹߋ৽ܥΫΤϦΛଧͱ͏ͱ͢Δͱྫ֎ •
ෳDBΛऔΓѻ͏͜ͱʹͳΔͷͰ switch_point ͱͯ༗ޮ • ࣗͣͱ M/S Λҙࣝ͢ΔΑ͏ͳએݴతهड़ʹͳΔ
IUUQTHJUIVCDPNFBHMFUNUTXJUDI@QPJOUCMPCNBTUFSTQFDNPEFMTSC TXJUDI@QPJOUͷઃఆྫ Ұ෦ൈਮ
IUUQTHJUIVCDPNFBHMFUNUTXJUDI@QPJOUCMPCNBTUFSTQFDNPEFMTSC TXJUDI@QPJOUͷઃఆྫ Ұ෦ൈਮ
खݩʹDBΛ࣋ͬͨ߹ͷσϝϦοτ • σʔλͷ४උ͕େม • ରʹ Slave ؚ͕·Ε͍ͯͯߋ৽ܥ SQL ଧͭΑ͏ͳ ίʔυΛॻ͍͍ͯΔ߹ɺຊ൪ͰϨϓϦ͕ࢭ·ͬͯࢮ
͵ • ݩͷDBεΩʔϚΛΔज़͕ඞཁ • ݩͷDBεΩʔϚΛखݩʹ؆୯ʹ࠶ݱ͢Δज़͕ඞཁ
ݩͷDBͷεΩʔϚΛΔज़
ݩͷDBͷεΩʔϚΛΔज़ • ۀͰ͍ͬͯΔεΩʔϚશͯ git Ͱཧ͞Ε͍ͯΔ • ͜͜ΛݟΕৗʹ࠷৽͕͋Δͱ͍͏ঢ়ଶ • ͜ͷϦϙδτϦͷεΩʔϚใΛ༻͢ΔΑ͏ʹσϓ ϩΠϓϩηεʹΈࠐ·Ε͍ͯΔ
• ฐࣾͷࣄྫʹؔΘΒͣɺmigration ֎ͷεΩʔϚͲ͜ ͔͠ΒʹҰݩཧ͞Ε͍ͯΔ͖
खݩʹDBΛ࣋ͬͨ߹ͷσϝϦοτ • σʔλͷ४උ͕େม • ରʹ Slave ؚ͕·Ε͍ͯͯߋ৽ܥ SQL ଧͭΑ͏ͳ ίʔυΛॻ͍͍ͯΔ߹ɺຊ൪ͰϨϓϦ͕ࢭ·ͬͯࢮ
͵ • ݩͷDBεΩʔϚΛΔज़͕ඞཁ • ݩͷDBεΩʔϚΛखݩʹ؆୯ʹ࠶ݱ͢Δज़͕ඞཁ
ݩͷDBͷεΩʔϚΛ खݩͰ؆୯ʹ࠶ݱ͢Δज़
ݩͷDBͷεΩʔϚΛ؆୯ʹ࠶ݱ͢Δज़ • Ұݩཧ͞Ε͍ͯΔεΩʔϚΛDBʹద༻ ͢Δͷ໘ • ໘ͳঢ়ଶͩͱεΩʔϚ͕ߋ৽͞Εͳ͘ͳΔ • Rails ʹ db:migrate
ͱ͍͏Έ͕͋Δͷ Ͱɺͦͷఔʹద༻ίετΛԼ͍͛ͨ
લఏ:εΩʔϚ͕ϦϙδτϦ ཧ͞Ε͍ͯΔ
͜ͷΛ ղܾ͢ΔΈΛ࡞ͬͯΈͨ
' # (JU)VC"1*$BMM 42- &YFDVUF ( 42-
db_supplier # SZPQFLPEC@TVQQMJFS
db_supplier (settings) DPOpHEBUBCBTFZNM
db_supplier (settings) DPOpHFOWJSPONFOUTEFWFMPQNFOUSC
DEMO
None
None
db_supplier Ͱ࣮ݱ͞Εͨ͜ͱ • ؆୯ʹҰݩཧ͞ΕͨεΩʔϚΛద༻͢Δ͜ ͱ͕Ͱ͖ͨ • ςετ࣌ʹ migration, fixture ͕͑ΔΑ͏ʹ
ͳͬͨ • ֎෦ͷDBͷײ৺ࣄΛݮΒͤͨ
db_supplier Ͱ࣮ݱ͍ͤͨ͜͞ͱ • εΩʔϚʹߋ৽ʹඋ͑ͯͲͷ࣌ͷͷ͕ద ༻͞Ε͍ͯΔ͔Θ͔ΔΑ͏ʹ͢Δ • db:seed ૬ͷͷΈࠐΊΔΑ͏ʹ • etc…
खݩʹDBΛ࣋ͬͨ߹ͷσϝϦοτ • σʔλͷ४උ͕େม • ରʹ Slave ؚ͕·Ε͍ͯͯߋ৽ܥ SQL ଧͭΑ͏ͳ ίʔυΛॻ͍͍ͯΔ߹ɺຊ൪ͰϨϓϦ͕ࢭ·ͬͯࢮ
͵ • ݩͷDBεΩʔϚΛΔज़͕ඞཁ • ݩͷDBεΩʔϚΛखݩʹ؆୯ʹ࠶ݱ͢Δज़͕ඞཁ
·ͱΊ
·ͱΊ • ֎෦ͷDBΛͦͷ··ར༻͢Δͱ։ൃ࣌ʹڝ߹ ͯ͠͠·͏ • खݩʹDBΛ࣋ͭʹͯ͠ద༻͕໘ • εΩʔϚͷཧͱద༻͕ඞཁ • gem
࡞ͬͯղܾͨ͠
࠷ޙʹ…
ͱ͍͑… • DBڞ༗ີ݁߹ʹͳΔ • ϞσϧͷϩδοΫ͕ॏෳͯ͠ଘࡏ͢ΔՄೳੑ • ҙਤ͍ͯ͠ͳ͍ͱ͜ΖͰDBΛ৮ΒΕ͍ͯΔՄ ೳੑ • API
͕༻ҙͰ͖ΔͳΒ API Λબ͖͢