fix: script

This commit is contained in:
Orion Kindel 2023-06-08 19:38:49 -05:00
parent c9995b30f8
commit 1f7404a91f
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 29 additions and 21 deletions

View File

@ -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/{}

29
scripts/build.sh Executable file
View File

@ -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