From be1007eaf3c69a3752219c5c853506d045a50e1d Mon Sep 17 00:00:00 2001 From: Carlos Chinchilla Date: Thu, 10 Feb 2022 14:27:31 -0600 Subject: [PATCH] print db schema --- README.md | 6 ++++++ db-schema.sh | 11 +++++++++++ system/db-schema.yaml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100755 db-schema.sh create mode 100644 system/db-schema.yaml diff --git a/README.md b/README.md index 70311120..e54171b8 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,12 @@ For tests written in `go`, you can add the name of the test that you want to run ./test.sh scribble TestCreateUserReturnsSuccess ``` +### Printing the DB schema + +For convenience, we include a script that prints the DB schema. + +To print the DB schema, run `./db-schema.sh` in your terminal. Once executed, you should see the table schemas printed on your screen. + ### Testing inside Kubernetes Make sure you have KIND installed. diff --git a/db-schema.sh b/db-schema.sh new file mode 100755 index 00000000..02db5890 --- /dev/null +++ b/db-schema.sh @@ -0,0 +1,11 @@ +FILE_PATH="system/db-schema.yaml" + +function cleanup { + docker-compose -f ${FILE_PATH} down --remove-orphans +} + +trap cleanup EXIT +cleanup + +docker-compose -f ${FILE_PATH} build main +docker-compose -f ${FILE_PATH} run main diff --git a/system/db-schema.yaml b/system/db-schema.yaml new file mode 100644 index 00000000..af9bfdf3 --- /dev/null +++ b/system/db-schema.yaml @@ -0,0 +1,30 @@ +version: '3' + +services: + main: + image: cockroachdb/cockroach:v20.1.4 + depends_on: + - cockroachdb + entrypoint: | + sh -c ' + /tools/wait-for-it.sh cockroachdb:26257 -t 60 + cat /migrations/* > /tmp/merged-latest.sql + cat /tmp/merged-latest.sql | ./cockroach sql --insecure --host cockroachdb + ./cockroach dump chatroach --insecure --host cockroachdb --dump-mode=schema + ' + volumes: + - ../devops:/tools + - ../devops/sql:/migrations + networks: + - fly + cockroachdb: + image: cockroachdb/cockroach:v20.1.4 + command: start --insecure + ports: + - 26257:26257 + networks: + - fly + +networks: + fly: + driver: bridge