Skip to content
wrench - Schema management tool for Cloud Spanner -
Go Python Makefile
Branch: master
Clone or download
110y Merge pull request #17 from mercari/update-bazel
update bazel version to 2.0.0
Latest commit 05152b4 Dec 24, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github update templates Sep 3, 2019
_examples initialize Sep 3, 2019
bazel use bazelisk Sep 9, 2019
bin use bazelisk Sep 9, 2019
cmd from xerrors to std errors Sep 5, 2019
pkg/spanner from xerrors to std errors Sep 5, 2019
.bazelrc create Docker container Sep 3, 2019
.bazelversion update bazel version to 2.0.0 Dec 24, 2019
.gitignore use bazelisk Sep 9, 2019
BUILD.bazel use nogo Sep 6, 2019
CONTRIBUTING.md initialize Sep 3, 2019
LICENSE initialize Sep 3, 2019
Makefile use bazelisk Sep 9, 2019
README.md Merge pull request #1 from execjosh/patch-1 Sep 3, 2019
WORKSPACE update bazel extensions Dec 1, 2019
go.mod use bazelisk Sep 9, 2019
go.sum use bazelisk Sep 9, 2019
main.go Merge branch 'master' into 1.13 Sep 5, 2019
tools.go use bazelisk Sep 9, 2019

README.md

wrench

wrench is a schema management tool for Cloud Spanner.

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

# create database with ./_examples/schema.sql
$ wrench create --directory ./_examples

# create migration file
$ wrench migrate create --directory ./_examples
_examples/migrations/000001.sql is created

# edit _examples/migrations/000001.sql
$ cat ./_examples/migrations/000001.sql
ALTER TABLE Singers ADD COLUMN LastName STRING(1024);

# execute migration
$ wrench migrate up --directory ./_examples

# load ddl from database to file ./_examples/schema.sql
$ wrench load --directory ./_examples

# finally, we have successfully migrated database!
$ 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);

Installation

Get binary from release page. Or, you can use Docker container: mercari/wrench.

Usage

Prerequisite

export SPANNER_PROJECT_ID=your-project-id
export SPANNER_INSTANCE_ID=your-instance-id
export SPANNER_DATABASE_ID=your-database-id

You can also specify project id, instance id and database id by passing them as command arguments.

Create database

$ wrench create --directory ./_examples

This creates the database with ./_examples/schema.sql.

Drop database

$ wrench drop

This just drops the database.

Reset database

wrench reset --directory ./_examples

This drops the database and then re-creates with ./_examples/schema.sql. Equivalent to drop and then create.

Load schema from database to file

$ wrench load --directory ./_examples

This loads schema DDL from database and writes it to ./_examples/schema.sql.

Create migration file

$ wrench migrate create --directory ./_examples

This creates a next migration file like _examples/migrations/000001.sql. You will write your own migration DDL to this file.

Execute migrations

$ wrench migrate up --directory ./_examples

This executes migrations. This also creates SchemaMigrations table into your database to manage schema version if it does not exist.

Apply single DDL/DML

$ wrench apply --ddl ./_examples/ddl.sql

This applies single DDL or DML.

Use wrench [command] --help for more information about a command.

Contribution

Please read the CLA carefully before submitting your contribution to Mercari. Under any circumstances, by submitting your contribution, you are deemed to accept and agree to be bound by the terms and conditions of the CLA.

https://www.mercari.com/cla/

License

Copyright 2019 Mercari, Inc.

Licensed under the MIT License.

You can’t perform that action at this time.