Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cloudspannerecosystem/wrench
wrench - Schema management tool for Cloud Spanner -
https://github.com/cloudspannerecosystem/wrench
cloud-spanner
Last synced: 3 months ago
JSON representation
wrench - Schema management tool for Cloud Spanner -
- Host: GitHub
- URL: https://github.com/cloudspannerecosystem/wrench
- Owner: cloudspannerecosystem
- License: mit
- Created: 2019-09-03T03:14:18.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-02T09:09:21.000Z (3 months ago)
- Last Synced: 2024-08-02T10:40:39.685Z (3 months ago)
- Topics: cloud-spanner
- Language: Go
- Size: 294 KB
- Stars: 230
- Watchers: 13
- Forks: 45
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-spanner - wrench - Schema management tool for Spanner. (Tools / ORM)
README
# wrench
`wrench` is a schema management tool for [Cloud Spanner](https://cloud.google.com/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.```sh
$ 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](https://github.com/cloudspannerecosystem/wrench/releases).
Or, you can use Docker container: [mercari/wrench](https://hub.docker.com/r/mercari/wrench).## Usage
### Prerequisite
```sh
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
```sh
$ wrench create --directory ./_examples
```This creates the database with `./_examples/schema.sql`.
### Drop database
```sh
$ wrench drop
```This just drops the database.
### Reset database
```sh
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
```sh
$ wrench load --directory ./_examples
```This loads schema DDL from database and writes it to `./_examples/schema.sql`.
### Create migration file
```sh
$ 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
```sh
$ 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
```sh
$ 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](CONTRIBUTING.md) 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
```2. Initialize a spanner instance.
```
$ make setup-emulator
```3. Run tests
```
$ make test
```## License
Copyright 2019 Mercari, Inc.
Licensed under the MIT License.