Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Migration checker as a CI
Search
Shimpei Otsubo
July 05, 2018
380
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.3k
Go と Wantedly の関係 / How Wantedly uses Go
potsbo
1
940
Deploy Flow at Wantedly
potsbo
2
1.1k
Wrap every method with just one line
potsbo
1
5.7k
Zero yen Keyboard
potsbo
6
3.4k
Kube - The core tool at Wantedly
potsbo
1
8.5k
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
Git: the NoSQL Database
bkeepers
PRO
432
67k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
830
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
It's Worth the Effort
3n
188
29k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
410
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
760
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
510
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͢Δੈք