spanner setup

2021-12-07T00:00:00.000Z

spanner setup

SetUp

  • gcp projectname nozomoto-project
  • instance name nozomoto-spanner
  • instance 1 node
    • we can use processing units for low price.
  • database name nozomoto-spanner
gcloud spanner instances create nozomoto-spanner --description="nozomoto" --config=regional-asia-northeast1 --nodes=1 --project nozomoto-project
gcloud spanner databases create nozomoto-spanner --instance nozomoto-spanner --project nozomoto-project

spanner-cli

gcloud auth application-default login
go install github.com/cloudspannerecosystem/spanner-cli@latest

## like mysql client
spanner-cli -p nozomoto-project -i nozomoto-spanner -d nozomoto-spanner

migration spanner

cat *.sql | spanner-cli -p nozomoto-project -i nozomoto-spanner -d nozomoto-spanner

Generate Database Side code

go install go.mercari.io/yo@latest
SPANNER_PROJECT_NAME=nozomoto-project
SPANNER_INSTANCE_NAME=nozomoto-spanner
SPANNER_DATABASE_NAME=nozomoto-spanner
yo $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o spanner_model

delete spanner instance

gcloud spanner instances delete nozomoto-spanner

using wrench migration

export SPANNER_PROJECT_ID=nozomoto-project
export SPANNER_INSTANCE_ID=nozomoto-spanner
export SPANNER_DATABASE_ID=nozomoto-spanner
go install github.com/cloudspannerecosystem/wrench@latest