Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
wrench - Schema Management Tool for Cloud Spanner -
Yuki Ito
February 06, 2020
Technology
2
950
wrench - Schema Management Tool for Cloud Spanner -
Yuki Ito
February 06, 2020
Tweet
Share
More Decks by Yuki Ito
See All by Yuki Ito
Microservices on Cloud Run @ KAUCHE
110y
0
68
KAUCHE Loves Go
110y
0
190
Evolution of Architecture @ Kauche
110y
3
240
Envoy as an API Gateway
110y
0
110
Microservices on Cloud Run + VPC Network
110y
0
230
How We Use Cloud Run and its Friends
110y
0
210
Custom Kubernetes Controllers at Mercari
110y
1
450
What Is the Go Workspace Mode
110y
4
1.1k
What Are We Doing as Merpay Architect
110y
0
1.3k
Other Decks in Technology
See All in Technology
AI Services 概要 / AI Services overview
oracle4engineer
PRO
0
170
Multi-Cloud Gatewayでデータを統治せよ!/ Data Federation with MCG
tutsunom
1
270
創業1年目のスタートアップでAWSコストを抑えるために取り組んでいること / How to Keep AWS Costs Down at a Startup
yuj1osm
3
2.1k
書籍を書きました。 そう、VS Codeで。
takumanakagame
4
4.4k
ユーザーテストガイドライン VERSION 2.0
kouzoukaikaku
0
1.3k
PHPのimmutable arrayとは
hnw
1
160
データ分析基盤の要件分析の話(202201_JEDAI)
yabooun
0
260
NGINXENG JP#2 - 1-NGINX-エンジニアリング勉強会-きょうの見どころ
hiropo20
0
110
USB PD で迎える AC アダプター大統一時代
puhitaku
2
1.9k
【NGK2023S】 ノードエディタ形式の画像処理ツール「Image-Processing-Node-Editor」
kazuhitotakahashi
0
280
cdk deployに必要な権限ってなんだ?
kinyok
0
170
OpenShiftクラスターのアップグレード自動化への挑戦! / OpenShift Cluster Upgrade Automation
skitamura7446
0
130
Featured
See All Featured
Designing Experiences People Love
moore
130
22k
Stop Working from a Prison Cell
hatefulcrawdad
263
18k
Practical Orchestrator
shlominoach
178
8.9k
Intergalactic Javascript Robots from Outer Space
tanoku
261
26k
Building Your Own Lightsaber
phodgson
96
4.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
254
12k
What's new in Ruby 2.0
geeforr
336
30k
A better future with KSS
kneath
230
16k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
44
14k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
182
15k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
227
16k
Designing for Performance
lara
600
65k
Transcript
wrench - Schema Management Tool for Cloud Spanner - GCPUG
Spanner Day Yuki Ito
Merpay Architect Team Backend Engineer Yuki Ito
wrench ʮGoͷ৽ػೳΛͬͨDBεΩʔϚ ཧπʔϧʯ https://gihyo.jp/magazine/SD/archive/2019/201911
wrench https://github.com/mercari/wrench https://hub.docker.com/r/mercari/wrench
wrench > wrench help Usage: wrench [command] Available Commands: create
drop reset load apply migrate
wrench create > cat ./_examples/schema.sql CREATE TABLE Singers ( SingerID
STRING(36) NOT NULL, FirstName STRING(1024), ) PRIMARY KEY(SingerID); > wrench create --directory ./_examples/
wrench create
wrench drop > wrench drop
wrench reset > wrench reset --directory ./_examples/
wrench load > wrench load --directory ./_examples/ > cat ./_examples/schema.sql
CREATE TABLE Singers ( SingerID STRING(36) NOT NULL, FirstName STRING(1024), ) PRIMARY KEY(SingerID);
wrench apply -ddl > cat ./_examples/ddl.sql ALTER TABLE Singers ADD
COLUMN LastName STRING(1024); > wrench apply --ddl ./_examples/ddl.sql
wrench apply -ddl
wrench apply -dml > cat ./_examples/dml.sql INSERT INTO Singers(SingerID, FirstName)
VALUES("1", "Yuki"); > wrench apply --dml ./_examples/dml.sql
wrench apply -dml
wrench migrate > cat ./_examples/migrations/000001.sql ALTER TABLE Singers ADD COLUMN
LastName STRING(1024); > wrench migrate up --directory ./_examples/ 1/up
wrench migrate
Development DB DB DB Instance
Development CREATE TABLE Singers ( SingerID STRING(36) NOT NULL, FirstName
STRING(1024), ) PRIMARY KEY(SingerID);
Development CREATE TABLE Singers ( SingerID STRING(36) NOT NULL, FirstName
STRING(1024), LastName STRING(1024), ) PRIMARY KEY(SingerID);
Development Apply Migration Load Schema Commit DDL Create DDL File
Write DDL Reset DB NG OK
Development > cat ./_examples/schema.sql CREATE TABLE Singers ( SingerID STRING(36)
NOT NULL, FirstName STRING(1024), ) PRIMARY KEY(SingerID);
Development
Development Apply Migration Load Schema Commit DDL Create DDL File
Write DDL Reset DB NG OK
Development > wrench migrate create --directory ./_examples/ _examples/migrations/000001.sql is created
> ls _examples/migrations/ 000001.sql
Development Apply Migration Load Schema Commit DDL Create DDL File
Write DDL Reset DB NG OK
Development > cat ./_examples/migrations/000001.sql ALTER TABLE Singers ADD COLUMN LastNamo
STRING(1024);
Development Apply Migration Load Schema Commit DDL Create DDL File
Write DDL Reset DB NG OK
Development > wrench migrate up --directory ./_examples/ 1/up
Development
Development typo!!
Development Apply Migration Load Schema Commit DDL Create DDL File
Write DDL Reset DB NG OK
Development > cat ./_examples/schema.sql CREATE TABLE Singers ( SingerID STRING(36)
NOT NULL, FirstName STRING(1024), ) PRIMARY KEY(SingerID); > wrench reset --directory ./_examples/
Development
Development Apply Migration Load Schema Commit DDL Create DDL File
Write DDL Reset DB NG OK
Development > cat ./_examples/migrations/000001.sql ALTER TABLE Singers ADD COLUMN LastName
STRING(1024);
Development Apply Migration Load Schema Commit DDL Create DDL File
Write DDL Reset DB NG OK
Development > wrench migrate up --directory ./_examples/ 1/up
Development
Development
Development Apply Migration Load Schema Commit DDL Create DDL File
Write DDL Reset DB NG OK
Development > wrench load --directory ./_examples/ > cat ./_examples/schema.sql CREATE
TABLE SchemaMigrations ( Version INT64 NOT NULL, Dirty BOOL NOT NULL, ) PRIMARY KEY(Version); CREATE TABLE Singers ( SingerID STRING(36) NOT NULL, FirstName STRING(1024), LastName STRING(1024), ) PRIMARY KEY(SingerID);
Development > wrench load --directory ./_examples/ > cat ./_examples/schema.sql CREATE
TABLE SchemaMigrations ( Version INT64 NOT NULL, Dirty BOOL NOT NULL, ) PRIMARY KEY(Version); CREATE TABLE Singers ( SingerID STRING(36) NOT NULL, FirstName STRING(1024), LastName STRING(1024), ) PRIMARY KEY(SingerID);
Development > wrench load --directory ./_examples/ > cat ./_examples/schema.sql CREATE
TABLE SchemaMigrations ( Version INT64 NOT NULL, Dirty BOOL NOT NULL, ) PRIMARY KEY(Version); CREATE TABLE Singers ( SingerID STRING(36) NOT NULL, FirstName STRING(1024), LastName STRING(1024), ) PRIMARY KEY(SingerID);
Development
Development Apply Migration Load Schema Commit DDL Create DDL File
Write DDL Reset DB NG OK
Development DB DB DB Instance
Deployment Create Tag Cloud Build Hook GCR Cloud Spanner GKE
Watch Push Migrate Deploy
Deployment Create Tag Cloud Build Hook GCR Cloud Spanner GKE
Watch Push Migrate Deploy
Deployment Migration Deployment Pipeline Cloud Spanner GKE
Deployment Migration Deployment Pipeline Cloud Spanner GKE
Deployment GKE Cloud Spanner Fetch Job Manifest ᶅ Exec `wrench
migrate` ᶄ Run Migration Job
Deployment GKE Cloud Spanner Fetch Job Manifest ᶅ Exec `wrench
migrate` ᶄ Run Migration Job
Deployment --- apiVersion: batch/v1 kind: Job metadata: name: db-migration spec:
template: spec: containers: - command: - /db/migrate.sh env: - name: SPANNER_INSTANCE_ID value: xxx - name: SPANNER_DATABASE_ID value: xxx - name: GCP_PROJECT_ID value: xxx - name: GOOGLE_APPLICATION_CREDENTIALS value: xxx image: gcr.io/xxxx…
Deployment GKE Cloud Spanner Fetch Job Manifest ᶅ Exec `wrench
migrate` ᶄ Run Migration Job
Deployment GKE Cloud Spanner Fetch Job Manifest ᶅ Exec `wrench
migrate` ᶄ Run Migration Job
Deployment wrench migrate up --directory /db
Deployment GKE Cloud Spanner Fetch Job Manifest ᶅ Exec `wrench
migrate` ᶄ Run Migration Job
Deployment Migration Deployment Pipeline Cloud Spanner GKE
Deployment Migration Deployment Pipeline Cloud Spanner GKE
Deployment GKE ᶄ Apply Deployment Manifest (Deploy New Container) ᶃ
Fetch Deployment Manifest
Deployment Create Tag Cloud Build Hook GCR Cloud Spanner GKE
Watch Push Migrate Deploy
Merpay Tech Fest 2020 https://events.merpay.com/techfest-2020