-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 72d18c4
Showing
45 changed files
with
2,538 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
name: Bug Report | ||
about: Report errors and problems | ||
labels: bug | ||
--- | ||
|
||
## Expected Behavior | ||
<!-- Write what you expected --> | ||
|
||
## Current Behavior | ||
<!-- Write current behavior --> | ||
|
||
## Steps to Reproduce | ||
<!-- Write steps to reproduce the bug --> | ||
|
||
1. | ||
2. | ||
3. | ||
4. | ||
|
||
## Context (Environment) | ||
|
||
* go-emv-code version: | ||
|
||
<!--- How has this issue affected you? What are you trying to accomplish? --> | ||
<!--- Providing context helps us come up with a solution that is most useful in the real world --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
name: Feature Request | ||
about: Requests for new features and improvements | ||
labels: enhancement | ||
--- | ||
|
||
## WHAT | ||
<!-- Write what you need --> | ||
|
||
## WHY | ||
<!-- Write the background of this issue --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bazel-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
builds: | ||
- binary: wrench | ||
goos: | ||
- windows | ||
- darwin | ||
- linux | ||
goarch: | ||
- amd64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
version = "1.0.0" | ||
|
||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
load("@bazel_gazelle//:def.bzl", "gazelle") | ||
load("@io_bazel_rules_docker//go:image.bzl", "go_image") | ||
|
||
# gazelle:prefix github.com/mercari/wrench | ||
gazelle(name = "gazelle") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["main.go"], | ||
importpath = "github.com/mercari/wrench", | ||
visibility = ["//visibility:private"], | ||
x_defs = {"github.com/mercari/wrench/cmd.Version": version}, | ||
deps = [ | ||
"//cmd:go_default_library", | ||
"//pkg/spanner:go_default_library", | ||
"@org_golang_x_xerrors//:go_default_library", | ||
], | ||
) | ||
|
||
go_binary( | ||
name = "wrench", | ||
embed = [":go_default_library"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_image( | ||
name = "image", | ||
embed = [":go_default_library"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Contributing | ||
|
||
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Copyright 2019 Mercari, Inc. | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.PHONY: test | ||
test: | ||
bazel test \ | ||
--test_env SPANNER_PROJECT_ID=$$SPANNER_PROJECT_ID \ | ||
--test_env SPANNER_INSTANCE_ID=$$SPANNER_INSTANCE_ID \ | ||
--test_env SPANNER_DATABASE_ID=$$SPANNER_DATABASE_ID \ | ||
--test_timeout 600 \ | ||
--test_output streamed \ | ||
--features race \ | ||
//... | ||
|
||
.PHONY: dep | ||
dep: | ||
go mod tidy | ||
bazel run //:gazelle | ||
bazel run //:gazelle -- \ | ||
update-repos \ | ||
-from_file go.mod \ | ||
-to_macro bazel/deps.bzl%wrench_deps | ||
|
||
.PHONY: build | ||
build: | ||
bazel build //:wrench | ||
|
||
.PHONY: image | ||
image: | ||
bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# wrench | ||
|
||
`wrench` is a schema management tool for [Cloud Spanner](https://cloud.google.com/spanner/). | ||
|
||
```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 releases page. | ||
|
||
## 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 wirte 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. | ||
|
||
|
||
## 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/](https://www.mercari.com/cla/) | ||
|
||
|
||
## License | ||
|
||
Copyright 2019 Mercari, Inc. | ||
|
||
Licensed under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") | ||
|
||
http_archive( | ||
name = "io_bazel_rules_go", | ||
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.19.3/rules_go-0.19.3.tar.gz"], | ||
sha256 = "313f2c7a23fecc33023563f082f381a32b9b7254f727a7dd2d6380ccc6dfe09b", | ||
) | ||
|
||
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains") | ||
go_rules_dependencies() | ||
go_register_toolchains() | ||
|
||
http_archive( | ||
name = "bazel_gazelle", | ||
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.18.1/bazel-gazelle-0.18.1.tar.gz"], | ||
sha256 = "be9296bfd64882e3c08e3283c58fcb461fa6dd3c171764fcc4cf322f60615a9b", | ||
) | ||
|
||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") | ||
gazelle_dependencies() | ||
|
||
git_repository( | ||
name = "com_google_protobuf", | ||
commit = "09745575a923640154bcf307fba8aedff47f240a", | ||
remote = "https://github.com/protocolbuffers/protobuf", | ||
shallow_since = "1558721209 -0700", | ||
) | ||
|
||
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") | ||
protobuf_deps() | ||
|
||
load("//:bazel/deps.bzl", "wrench_deps") | ||
wrench_deps() | ||
|
||
http_archive( | ||
name = "io_bazel_rules_docker", | ||
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.9.0/rules_docker-v0.9.0.tar.gz"], | ||
sha256 = "e513c0ac6534810eb7a14bf025a0f159726753f97f74ab7863c650d26e01d677", | ||
strip_prefix = "rules_docker-0.9.0", | ||
) | ||
|
||
load( | ||
"@io_bazel_rules_docker//repositories:repositories.bzl", | ||
container_repositories = "repositories", | ||
) | ||
container_repositories() | ||
|
||
load( | ||
"@io_bazel_rules_docker//go:image.bzl", | ||
_go_image_repos = "repositories", | ||
) | ||
|
||
_go_image_repos() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE Singers ADD COLUMN LastName STRING(1024); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE Singers ( | ||
SingerID STRING(36) NOT NULL, | ||
FirstName STRING(1024), | ||
) PRIMARY KEY(SingerID); |
Empty file.
Oops, something went wrong.