From 1f7404a91f541c09824de54149043788624a4dcc Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Thu, 8 Jun 2023 19:38:49 -0500 Subject: [PATCH] fix: script --- scripts/build-reference.sh | 21 --------------------- scripts/build.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 21 deletions(-) delete mode 100755 scripts/build-reference.sh create mode 100755 scripts/build.sh diff --git a/scripts/build-reference.sh b/scripts/build-reference.sh deleted file mode 100755 index 23e697e..0000000 --- a/scripts/build-reference.sh +++ /dev/null @@ -1,21 +0,0 @@ -#! /usr/bin/bash - -$rev=${1:-HEAD} - -if [ "$rev" = "HEAD" ]; then - $port = 5432 -else - $port = 5433 -fi - -while read line; do export $line; done < ./.env - -psql \ - --echo-all \ - postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$port/$POSTGRES_DB \ - --command="drop schema public cascade; create schema public;" - -ls ./migrations/ | xargs -I{} psql \ - --echo-all \ - postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5433/$POSTGRES_DB \ - --file=./migrations/{} diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..b9b5038 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,29 @@ +#! /usr/bin/bash + +rev=${1:-HEAD} + +if [[ -n $(git status --porcelain) ]]; then + echo "git working tree dirty"; + exit 1; +fi + +if [[ "$rev" = "HEAD" ]]; then + head="" + port=5432 +else + head=$(git show --format=format:%h -q) + git reset "$rev" + port=5433 +fi + +while read line; do export $line; done < ./.env + +url=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$port/$POSTGRES_DB + +psql --echo-all $url --command="drop schema public cascade; create schema public;" + +ls ./migrations/ | xargs -I{} psql --echo-all $url --file=./migrations/{} + +if [[ -n "$head" ]]; then + git reset "$head" +fi