fix: add diff, env
This commit is contained in:
parent
e52348cdd1
commit
db9cad3520
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
.env
|
||||
tmp
|
||||
|
@ -1,9 +1,11 @@
|
||||
#! /usr/bin/bash
|
||||
|
||||
source ./scripts/env.sh
|
||||
|
||||
rev=${1:-HEAD}
|
||||
|
||||
if [[ -n $(git status --porcelain) ]]; then
|
||||
echo "git working tree dirty";
|
||||
echo "git working tree dirty" 1>&2;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
@ -12,18 +14,28 @@ if [[ "$rev" = "HEAD" ]]; then
|
||||
port=5432
|
||||
else
|
||||
head=$(git show --format=format:%h -q)
|
||||
git reset "$rev"
|
||||
git reset "$rev" --quiet --hard
|
||||
port=5433
|
||||
fi
|
||||
|
||||
while read line; do export $line; done < ./.env
|
||||
switch_back_to_head() {
|
||||
if [[ -n "$head" ]]; then
|
||||
git reset --quiet --hard "$head"
|
||||
fi
|
||||
}
|
||||
trap 'switch_back_to_head' EXIT
|
||||
|
||||
url=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$port/$POSTGRES_DB
|
||||
url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$port/$POSTGRES_DB
|
||||
|
||||
psql --echo-all $url --command="drop schema public cascade; create schema public;"
|
||||
psql \
|
||||
--quiet \
|
||||
$url \
|
||||
--command="drop schema public cascade; create schema public;" \
|
||||
1>/dev/null
|
||||
|
||||
ls ./migrations/ | xargs -I{} psql --echo-all $url --file=./migrations/{}
|
||||
|
||||
if [[ -n "$head" ]]; then
|
||||
git reset "$head"
|
||||
fi
|
||||
ls ./migrations/ | xargs -I{} \
|
||||
psql \
|
||||
--quiet \
|
||||
$url \
|
||||
--file=./migrations/{} \
|
||||
1>/dev/null
|
||||
|
23
scripts/diff.sh
Executable file
23
scripts/diff.sh
Executable file
@ -0,0 +1,23 @@
|
||||
#! /usr/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
source ./scripts/env.sh
|
||||
|
||||
rev=${1:-}
|
||||
|
||||
head_url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB
|
||||
base_url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5433/$POSTGRES_DB
|
||||
|
||||
if [[ -z "$rev" ]]; then
|
||||
echo "revision to diff is required";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
docker compose up -d
|
||||
|
||||
./scripts/build.sh $rev
|
||||
./scripts/build.sh HEAD
|
||||
|
||||
echo "migrate from $rev => HEAD" 1>&2
|
||||
migra $base_url $head_url
|
3
scripts/env.sh
Executable file
3
scripts/env.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#! /usr/bin/bash
|
||||
|
||||
while read line; do export $line; done < ./.env
|
Loading…
Reference in New Issue
Block a user