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
920
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.4k
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
HDC tutorial
michielstock
2
740
What's in a price? How to price your products and services
michaelherold
247
13k
How to make the Groovebox
asonas
2
2.3k
Embracing the Ebb and Flow
colly
88
5.1k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
230
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Odyssey Design
rkendrick25
PRO
2
730
So, you think you're a good person
axbom
PRO
2
2.1k
Automating Front-end Workflow
addyosmani
1370
210k
Code Review Best Practice
trishagee
74
20k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
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͢Δੈք