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
Web開発を支えるマイグレーションツールについて / sqldef introduction ...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
yudppp
December 07, 2019
Programming
3.7k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Web開発を支えるマイグレーションツールについて / sqldef introduction for psql users
第11回 PostgreSQLアンカンファレンス@東京で発表する資料
https://pgunconf.connpass.com/event/155951/
yudppp
December 07, 2019
More Decks by yudppp
See All by yudppp
開発者にもコーディングエージェントにも働きやすい環境を整える
yudppp
1
170
型安全なDrag and Dropの設計を考える
yudppp
5
1.1k
未知のプログラミング言語にChatGPTと共に挑む
yudppp
0
560
SaaSフロントエンド開発の現場で求められる技術 / Technologies for SaaS Frontend Development in the Field
yudppp
2
300
2019年 HRBrainの技術的挑戦 / hrbain technology challenge 2019
yudppp
3
1.5k
ISUCON向けのツールを作った話 / isutools
yudppp
1
360
Row Level Securityはマルチテナントの銀の弾丸になりうるのか / Row Level Security is silver bullet for multitenancy?
yudppp
23
34k
Webサービス開発に必要な統計学入門 / study of statistics for web developers
yudppp
1
380
メジャーな Live Reloaderの違いをちゃんと調べて見た / Compare major live reloader of Go
yudppp
1
2k
Other Decks in Programming
See All in Programming
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
740
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.4k
contenteditable と日本語入力に向き合う
colorful12
0
200
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
490
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
16k
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
140
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
AmebaブログはKMPから卒業します
kmars0605
0
160
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
410
JIS keyboard support in Omarchy
lef237
0
110
Simple Storage Service(S3) is not simple
iwatsukayura
0
280
Featured
See All Featured
Side Projects
sachag
456
43k
Designing Powerful Visuals for Engaging Learning
tmiket
1
600
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Why Our Code Smells
bkeepers
PRO
340
58k
Code Review Best Practice
trishagee
74
20k
The Curious Case for Waylosing
cassininazir
1
570
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Deep Space Network (abreviated)
tonyrice
0
370
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
540
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Transcript
Web開発を⽀える マイグレーションツールについて 第11回 PostgreSQLアンカンファレンス@東京
⾃⼰紹介 @yudppp 株式会社HRBrain CTO 好きな⾔葉: 冪等性 嫌いなモノ: 浮動⼩数点の誤差 基本的にWebエンジニア
⽬標評価管理クラウド
HRBrainとは • ⽬標と評価を管理するクラウドSaaSを作って いる会社です。 • リリース開始からもうすぐで3年
先⽇Buildersconにて Row Level Securityは マルチテナントの 銀の弾丸になりうるのか という話をしました https://speakerdeck.com/yudppp/row-level-security-is-silver-bullet-for-multitenancy
概要 • SaaS開発していく上でリリース頻度を⾼く開 発していくには真のマルチテナント(全ての会 社の情報が⼀つのDB)にしていきたいが、セ キュリティ的な不安要素をPostgreSQLの RowLevelSecurityを使って解決した話
PostgreSQL Conference Japanで この内容とマイグレーションについて話そうとしたら CfP落ちました。。
現在のリリース頻度 • 週に2回リリース • 毎回ではないがSQLのマイグレーションが頻 繁に必要
みなさんマイグレーション の管理どうされていますか
元々のマイグレーション管理 gooseというGo製のToolを利⽤
起きた問題① Aさん「81_modify_user_birthday_col.sql」 Bさん「81_add_era_table.sql」 Aさん「Merge!」 Bさん「Merge!」 CI 「Test / Deploy 失敗!」
CIでTest実⾏した瞬間は ⼤丈夫なので Mergeされる前に 検知するのが難しい
起きた問題② 前提: みんなでdev環境⼀つを共有していてfeature ブランチをSlackで告知すれば好きなタイミ ングであげれる運⽤ (本当はfeatureブランチごとdeployしたい)
起きた問題② Bさん「令和追加した確認するのでdev使い ます。」 CI 「Deployed!」 Migrationがなぜか呼ばれない。。 誰かがあげたMigrationがdownされてない
この運⽤をしていると Migrationを戻すタイミング が難しい
解決策を探す
k0kubun/sqldef The easiest idempotent MySQL/PostgreSQL schema management by SQL. This
is inspired by Ridgepole but using SQL, so there's no need to remember Ruby DSL. 定義したschema.sqlとDB接続した情報を⽐較し ていい感じにALTER⽂を流してくれる Go製なのでbinaryだけで動く
https://github.com/k0kubun/sqldef
どうなるか 常にschemaファイルとDBの状態が等しくな るので、上記のような問題は起きない。 もし起きたとしても、schemaファイルが Conflictするので気づける。
sqldefの内部実装 Vitess(Vitess is a database clustering system for horizontal scaling
of MySQL)のsqlparser のsourceを拡張して作られている。 information_schema.table_constraintsあた りをSELECTした結果を元にCREATE⽂を Buildしている。
既知の課題 基本的な構⽂は対応しているが、Vitessから 派⽣したこともありPostgreSQLのあまり使わ れない構⽂が未対応だったりする。(そう例え ばRowLevelSecurityとか) sqldefのPostgreSQLのユーザーがそこまで多 くなさそう。
まとめ 冪等性が担保された安全な⽣活がしたい。 sqldefをPostgreSQLで使うユーザーを増やし て、より洗礼されたツールになってほしい 今⽇の発表で1⼈でもユーザーが増えたら嬉 しい
参考資料 •SQLで羃等にDBスキーマ管理ができるツー ル「sqldef」を作った (https:// k0kubun.hatenablog.com/entry/2018/08/ 25/114455) •http://vitess.io/