Upgrade to Pro — share decks privately, control downloads, hide ads and more …

wrench - Schema Management Tool for Cloud Spann...

Yuki Ito
February 06, 2020

wrench - Schema Management Tool for Cloud Spanner -

Yuki Ito

February 06, 2020
Tweet

More Decks by Yuki Ito

Other Decks in Technology

Transcript

  1. wrench create > cat ./_examples/schema.sql CREATE TABLE Singers ( SingerID

    STRING(36) NOT NULL, FirstName STRING(1024), ) PRIMARY KEY(SingerID); > wrench create --directory ./_examples/
  2. wrench load > wrench load --directory ./_examples/ > cat ./_examples/schema.sql

    CREATE TABLE Singers ( SingerID STRING(36) NOT NULL, FirstName STRING(1024), ) PRIMARY KEY(SingerID);
  3. wrench apply -ddl > cat ./_examples/ddl.sql ALTER TABLE Singers ADD

    COLUMN LastName STRING(1024); > wrench apply --ddl ./_examples/ddl.sql
  4. wrench apply -dml > cat ./_examples/dml.sql INSERT INTO Singers(SingerID, FirstName)

    VALUES("1", "Yuki"); > wrench apply --dml ./_examples/dml.sql
  5. wrench migrate > cat ./_examples/migrations/000001.sql ALTER TABLE Singers ADD COLUMN

    LastName STRING(1024); > wrench migrate up --directory ./_examples/ 1/up
  6. Development CREATE TABLE Singers ( SingerID STRING(36) NOT NULL, FirstName

    STRING(1024), LastName STRING(1024), ) PRIMARY KEY(SingerID);
  7. Development > cat ./_examples/schema.sql CREATE TABLE Singers ( SingerID STRING(36)

    NOT NULL, FirstName STRING(1024), ) PRIMARY KEY(SingerID);
  8. Development > cat ./_examples/schema.sql CREATE TABLE Singers ( SingerID STRING(36)

    NOT NULL, FirstName STRING(1024), ) PRIMARY KEY(SingerID); > wrench reset --directory ./_examples/
  9. 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);
  10. 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);
  11. 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);
  12. 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…