• Stars
    star
    236
  • Rank 170,480 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created over 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

wrench - Schema management tool for Cloud Spanner -

wrench

wrench is a schema management tool for Cloud Spanner.

Please feel free to report issues and send pull requests, but note that this application is not officially supported as part of the Cloud Spanner product.

$ 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.

Contributions

Please read the contribution guidelines before submitting pull requests.

How to run tests locally

  1. Start spanner emulator.
$ docker run --rm -it -p 9010:9010 -p 9020:9020 gcr.io/cloud-spanner-emulator/emulator:1.5.0
  1. Initialize a spanner instance.
$ make setup-emulator
  1. Run tests
$ make test

License

Copyright 2019 Mercari, Inc.

Licensed under the MIT License.

More Repositories

1

yo

yo is a command-line tool to generate Go code for Google Cloud Spanner.
Go
309
star
2

spanner-cli

Interactive command line tool for Cloud Spanner
Go
229
star
3

autoscaler

Automatically scale the capacity of your Spanner instances based on their utilization.
JavaScript
86
star
4

memefish

memefish is the foundation to analyze Spanner SQL
Go
71
star
5

spanner-dump

Command line tool for exporting a Cloud Spanner database in text format
Go
39
star
6

spanner-schema-diff-tool

Compare two Cloud Spanner Schema (DDL) files, determine the differences and generate the required ALTER statements to convert one schema to the other.
Java
32
star
7

spanner-truncate

spanner-truncate is a tool to delete all rows from the tables in a Cloud Spanner database without deleting tables themselves.
Go
27
star
8

spanner-change-watcher

Cloud Spanner Change Watcher and Publisher - Detects data changes in Cloud Spanner databases
Java
25
star
9

gcsb

Cloud Spanner load generator to load test your application and pre-warm the database before launch
Go
25
star
10

spanner-bench

Google Cloud Spanner Query Planner Benchmarking
Go
24
star
11

spool

A CLI tool to manage Cloud Spanner databases for testing.
Go
24
star
12

spanner-proxy

An easy way to create Google Cloud Spanner proxies.
Go
20
star
13

liquibase-spanner

Java
19
star
14

spanner-change-streams-tail

CLI to tail Cloud Spanner change streams
Go
19
star
15

spanner-gaming-sample

This repository sets up a sample microservice architecture to highlight how Cloud Spanner integrates with other cloud technologies.
Go
18
star
16

pgadapter

A proxy that translates the wire protocol from Postgres to Cloud Spanner.
Java
14
star
17

spanner-benchmarks-tutorial

Hands-on lab/tutorial for generating benchmarks for Google Cloud Spanner
13
star
18

sqltools-cloud-spanner-driver

TypeScript
10
star
19

machmeter

Quickly perform Cloud Spanner POCs using Machmeter.
Java
8
star
20

scheduled-backups

Showing how to use Cloud Scheduler and Cloud Functions to configure a schedule for creating Cloud Spanner backups.
Go
8
star
21

spanner-sqlalchemy-demo

A demo application for Cloud Spanner SQLAlchemy ORM, simple ranking API for gaming use cases.
Python
7
star
22

dynamodb-adapter

Go
6
star
23

omegatrade

Sample application for Spanner written in Node.js.
TypeScript
6
star
24

emulator-samples

Samples for using Cloud Spanner Emulator
C++
5
star
25

website

Static website for cloudspannerecosystem.dev
CSS
5
star
26

sampledb

Quickly get a sample database into Cloud Spanner
Python
5
star
27

spanner-ai

Spanner Integrations with Vertex AI.
Python
4
star
28

spanner-stress-test-demo

Python
3
star
29

spanner-terraform

Google Cloud Spanner with Terraform
3
star
30

cassandra-to-spanner-proxy

Go
2
star
31

spanner-analytics

Python
2
star
32

appengine-java-sample

Sample for using Cloud Spanner from App Engine Java
Java
2
star
33

spanner-table-copy-pipeline

Java
2
star
34

spanner-rest-cmdlets

PowerShell
2
star
35

spanner-terraform-example

Sample terraform templates for Cloud Spanner.
HCL
1
star