30 lines
595 B
Bash
30 lines
595 B
Bash
|
#! /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
|