db/scripts/build.sh

53 lines
1.1 KiB
Bash
Raw Normal View History

#! /bin/bash
2023-06-09 00:38:49 +00:00
2023-07-17 03:47:16 +00:00
set -e
2023-06-27 23:43:04 +00:00
2023-07-17 19:44:40 +00:00
source ./scripts/common.sh
source ./scripts/env.sh ./.env.schema
2023-06-09 01:29:13 +00:00
2023-07-17 03:47:16 +00:00
base_or_head="$1"
rev="$2"
2023-06-09 00:38:49 +00:00
2023-07-17 03:47:16 +00:00
if [[ "$base_or_head" = "head" ]]; then
2023-06-09 00:38:49 +00:00
port=5433
2023-07-17 03:47:16 +00:00
else
port=5432
2023-06-09 00:38:49 +00:00
fi
2023-07-17 19:44:40 +00:00
docker compose down "$base_or_head"
url="postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$port"
isready() {
until pg_isready -p "$port" 1>/dev/null; do true; done;
}
2023-06-09 01:29:13 +00:00
2023-07-17 19:44:40 +00:00
initdb() {
dropdb=$(mktemp)
echo "drop database dnim with (force);" > "$dropdb"
psql --quiet "$url/postgres" -f "$dropdb" || true
psql --quiet "$url/postgres" -c "create database dnim"
}
if [[ "$rev" = "empty" ]]; then
docker compose up -d "$base_or_head"
isready
initdb
exit 0
fi
git worktree remove --force "./$base_or_head" || true
rm -rf "./$base_or_head" || true
git worktree add "./$base_or_head" --detach "$rev"
cp docker-compose.yml "./$base_or_head/docker-compose.yml"
cp .env.schema "./$base_or_head/.env.schema"
cd "./$base_or_head"
docker compose up -d "$base_or_head"
cd "../$base_or_head"
2023-07-17 03:47:16 +00:00
2023-07-17 19:44:40 +00:00
isready
initdb
2023-07-19 02:31:56 +00:00
ls ./schema/ | xargs -I{} bash -c "set -e; $(declare -f query_file); query_file \"$url/dnim\" ./schema/{}"