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
アジャイルチームがらしさを発揮するための目標づくり / Making the goal and enabling the team
kakehashi
3
130
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
Introduction to Works of ML Engineer in LY Corporation
lycorp_recruit_jp
0
140
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
250
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
870
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
390
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
690
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
880
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.2k
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.5k
Lexical Analysis
shigashiyama
1
150
Featured
See All Featured
Producing Creativity
orderedlist
PRO
341
39k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Side Projects
sachag
452
42k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
420
Designing Experiences People Love
moore
138
23k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
Code Reviewing Like a Champion
maltzj
520
39k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
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 Λબ͖͢