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
Migration checker as a CI
Search
Shimpei Otsubo
July 05, 2018
360
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Migration checker as a CI
Shimpei Otsubo
July 05, 2018
More Decks by Shimpei Otsubo
See All by Shimpei Otsubo
Copy Kubernetes Clusters Really Fast
potsbo
3
5.2k
Go と Wantedly の関係 / How Wantedly uses Go
potsbo
1
910
Deploy Flow at Wantedly
potsbo
2
1.1k
Wrap every method with just one line
potsbo
1
5.6k
Zero yen Keyboard
potsbo
6
3.3k
Kube - The core tool at Wantedly
potsbo
1
8.3k
k8s - Kubernetes 8 Factors
potsbo
12
11k
コンテンツ作成に集中するためのプレゼンテーション Tips / Presentation with Confidence
potsbo
7
42k
ConfigMap vs Secret #k8sjp
potsbo
1
1.5k
Featured
See All Featured
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
150
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Prompt Engineering for Job Search
mfonobong
0
350
For a Future-Friendly Web
brad_frost
183
10k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The Limits of Empathy - UXLibs8
cassininazir
1
360
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
The browser strikes back
jonoalderson
0
1.3k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
170
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
750
A Tale of Four Properties
chriscoyier
163
24k
Transcript
©2018 Wantedly, Inc. Migration checker as a CI ΦϨΦϨCIͷ࡞Γํ දࢀಓ.rb
#36 5.Jul.2018 - Shimpei Otsubo - @potsbo
©2018 Wantedly, Inc. 3BJMTͷNJHSBUJPOΕͰࢮ͵
©2018 Wantedly, Inc. खಈEFQMPZ͍ͯ͠Δ ECNJHSBUFEFQMPZ͢Δਓ͕Δ (JU)VCΛத৺ʹͨ͠։ൃ 8BOUFEMZͷSBJMT։ൃࣄ
©2018 Wantedly, Inc. ࣗಈNJHSBUJPOͰ͖ͳ͍ͱ͢Δ ͤΊͯࣗಈͰQFOEJOH͕͋Δ͔Γ͍ͨʂʂ NJHSBUJPOΕΔ͕͋Δ 13NFSHFલʹඞͣNJHSBUJPO͢Δੈք
©2018 Wantedly, Inc. push CI? ? pending... success!!!
©2018 Wantedly, Inc. push migration checking CI? ? pending... success!!!
migration? ready!!
©2018 Wantedly, Inc. push Third Party migration checking CI? pending...
success!!! migration? ready!! Bad ֎෦ʹ%#ΛҰ෦ͰFYQPTFͨ͘͠ͳ͍ $*͕٧·Γ͘͢ͳΔ
©2018 Wantedly, Inc. First Party migration checking CI? Good CI
push pending... success!!! migration? ready!! ֎෦ʹ%#ΛFYQPTF͠ͳͯ͘ྑ͍ ΞϓϦέʔγϣϯςετΛॏ͘͠ͳ͍
©2018 Wantedly, Inc.
©2018 Wantedly, Inc. NAME = 'wantedly/migration-checker' post '/builds' do params
= JSON.parse request.body.read repo = params['repository']['full_name'] hash = params['head'] Octokit.create_status(repo, hash, :pending, context: NAME) state = :success desc = "Database is ready" unless SchemaMigration.pending_versions(user, repo, hash).empty? state = :failure description = "Pending migration exists: #{pendings.join(' ')}" end Octokit.create_status(repo, hash, state, context: NAME, description: desc) 'ok' end ©2018 Wantedly, Inc. IUUQTPDUPLJUHJUIVCJPPDUPLJUSC0DUPLJU$MJFOU4UBUVTFTIUNM
©2018 Wantedly, Inc. PATH = 'db/migrate' class SchemaMigration < ActiveRecord::Base
def self.pending_versions(repo, ref) versions = Octokit.contents(slug, path: PATH, ref: ref). map { |c| c.name.split('_')[0] } key = "#{repo.upcase}_DATABASE_URL" ActiveRecord::Base.establish_connection(ENV[key]) migrated = SchemaMigration.pluck(:version) ActiveRecord::Base.connection.close versions - migrated end end ©2018 Wantedly, Inc. database=# \d schema_migrations Table "public.schema_migrations" Column | Type | Modifiers ---------+-------------------+----------- version | character varying | not null
©2018 Wantedly, Inc. ೝূ RVFVF͢Δ QJOHड ࣗಈXFCIPPLઃఆ ઃఆGJMF ΦϚέଞʹΒͳ͍ͱ͍͚ͳ͍͜ͱ
©2018 Wantedly, Inc. 13NFSHFલʹඞͣNJHSBUJPO͢Δੈք