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
Web開発を支えるマイグレーションツールについて / sqldef introduction ...
Search
yudppp
December 07, 2019
Programming
2
3.2k
Web開発を支えるマイグレーションツールについて / sqldef introduction for psql users
第11回 PostgreSQLアンカンファレンス@東京で発表する資料
https://pgunconf.connpass.com/event/155951/
yudppp
December 07, 2019
Tweet
Share
More Decks by yudppp
See All by yudppp
未知のプログラミング言語にChatGPTと共に挑む
yudppp
0
370
SaaSフロントエンド開発の現場で求められる技術 / Technologies for SaaS Frontend Development in the Field
yudppp
2
160
2019年 HRBrainの技術的挑戦 / hrbain technology challenge 2019
yudppp
3
1.3k
ISUCON向けのツールを作った話 / isutools
yudppp
1
250
Row Level Securityはマルチテナントの銀の弾丸になりうるのか / Row Level Security is silver bullet for multitenancy?
yudppp
21
30k
Webサービス開発に必要な統計学入門 / study of statistics for web developers
yudppp
1
260
メジャーな Live Reloaderの違いをちゃんと調べて見た / Compare major live reloader of Go
yudppp
1
1.8k
今年お世話になったnpm module
yudppp
1
900
Goで社内向け管理画面を楽に作る方法
yudppp
5
10k
Other Decks in Programming
See All in Programming
Compose Hot Reload is here, stop re-launching your apps! (Android Makers 2025)
zsmb
1
480
コンテナでLambdaをデプロイするときに知っておきたかったこと
_takahash
0
180
Go1.24 go vetとtestsアナライザ
kuro_kurorrr
2
840
The Weight of Data: Rethinking Cloud-Native Systems for the Age of AI
hollycummins
0
270
データベースエンジニアの仕事を楽にする。PgAssistantの紹介
nnaka2992
9
4.5k
Making TCPSocket.new "Happy"!
coe401_
1
120
プロダクト横断分析に役立つ、事前集計しないサマリーテーブル設計
hanon52_
2
380
Bedrock×MCPで社内ブログ執筆文化を育てたい!
har1101
6
890
DomainException と Result 型で作る型安全なエラーハンドリング
karszawa
0
890
Devin入門と最近のアップデートから見るDevinの進化 / Introduction to Devin and the Evolution of Devin as Seen in Recent Update
rkaga
9
4.7k
SEAL - Dive into the sea of search engines - Symfony Live Berlin 2025
alexanderschranz
1
130
国漢文混用体からHolloまで
minhee
1
170
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
133
9.2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
19
1.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
104
19k
Side Projects
sachag
452
42k
Building a Modern Day E-commerce SEO Strategy
aleyda
40
7.2k
GraphQLとの向き合い方2022年版
quramy
46
14k
StorybookのUI Testing Handbookを読んだ
zakiyama
29
5.6k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.3k
Bash Introduction
62gerente
611
210k
Adopting Sorbet at Scale
ufuk
76
9.3k
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/