chore: update migrations
This commit is contained in:
parent
c32adb2107
commit
21957cf791
@ -1 +1 @@
|
||||
Subproject commit 4bc2f54cfd2abdbf4a51d9648ec12ce80dd58ca5
|
||||
Subproject commit f33340900061269c067e915082e827b07af1b8ad
|
@ -63,11 +63,6 @@ create function public.usr_root()
|
||||
language sql
|
||||
as $$select * from public.usr where tag = public.usr_tag_of_string('root')$$;
|
||||
|
||||
insert into public.usr
|
||||
(tag, password, email)
|
||||
values
|
||||
(usr_tag_of_string('root'), hashed_text_of_string(''), email_of_string(''));
|
||||
|
||||
create function public.do_check_usr_tag()
|
||||
returns trigger
|
||||
stable
|
||||
|
@ -7,9 +7,6 @@ create table public.grp
|
||||
, tag public.grp_tag not null unique
|
||||
);
|
||||
|
||||
insert into public.grp (tag)
|
||||
values (grp_tag_of_string('admins'));
|
||||
|
||||
create function public.grp_admins()
|
||||
returns public.grp
|
||||
stable
|
||||
|
@ -14,7 +14,7 @@ else
|
||||
port=5432
|
||||
fi
|
||||
|
||||
docker compose down "$base_or_head"
|
||||
docker compose down "$base_or_head" &>/dev/null
|
||||
|
||||
url="postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$port"
|
||||
|
||||
@ -25,28 +25,28 @@ isready() {
|
||||
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"
|
||||
psql --quiet "$url/postgres" -f "$dropdb" &>/dev/null || true
|
||||
psql --quiet "$url/postgres" -c "create database dnim" &>/dev/null
|
||||
}
|
||||
|
||||
if [[ "$rev" = "empty" ]]; then
|
||||
docker compose up -d "$base_or_head"
|
||||
docker compose up -d "$base_or_head" &>/dev/null
|
||||
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"
|
||||
git worktree remove --force "./$base_or_head" &>/dev/null || true
|
||||
rm -rf "./$base_or_head" &>/dev/null || true
|
||||
git worktree add "./$base_or_head" --detach "$rev" &>/dev/null
|
||||
|
||||
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"
|
||||
docker compose up -d "$base_or_head" &>/dev/null
|
||||
cd "../$base_or_head"
|
||||
|
||||
isready
|
||||
initdb
|
||||
ls ./schema/ | xargs -I{} bash -c "set -e; $(declare -f query_file); query_file \"$url/dnim\" ./schema/{}"
|
||||
ls ./schema/ | xargs -I{} bash -c "set -e; $(declare -f query_file); query_file \"$url/dnim\" ./schema/{} 2>/dev/null"
|
||||
|
@ -13,12 +13,15 @@ revs_ct=$(echo "$revs" | wc -l)
|
||||
do_i() {
|
||||
base=$(echo "$revs" | tail --lines "+$1" | head -n 1)
|
||||
if [[ -f "./migrations/${base}_skipped.sql" ]]; then
|
||||
echo "skip $base"
|
||||
return
|
||||
fi
|
||||
|
||||
for j in $(seq "$(($1 + 1))" "$revs_ct"); do
|
||||
head=$(echo "$revs" | tail --lines "+$j" | head -n 1)
|
||||
migration="./migrations/${base}_to_${head}.sql"
|
||||
echo "building $migration..."
|
||||
|
||||
set +e
|
||||
out=$(./scripts/diff.sh "$base" "$head")
|
||||
status="$?"
|
||||
@ -26,12 +29,14 @@ do_i() {
|
||||
|
||||
if [[ "$status" = "1" && "$out" = *"head failed to build"* ]]; then
|
||||
echo "" > "./migrations/${head}_skipped.sql"
|
||||
echo "wrote ./migrations/${head}_skipped.sql"
|
||||
continue
|
||||
elif [[ "$status" = "1" ]]; then
|
||||
echo out
|
||||
exit 1
|
||||
else
|
||||
echo "$out" > "$migration"
|
||||
echo "wrote $migration"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
@ -29,6 +29,7 @@ else
|
||||
revs_to_run="$log"
|
||||
|
||||
if [[ "$rev_last" = "$rev_most_recent" ]]; then
|
||||
query_file "$POSTGRES_URI/dnim" "migrations/ensure_seeded.sql"
|
||||
echo "all caught up! :)"
|
||||
exit 0
|
||||
elif [[ "$rev_last" != "empty" ]]; then
|
||||
@ -57,4 +58,6 @@ else
|
||||
exit 1
|
||||
fi
|
||||
done;
|
||||
|
||||
query_file "$POSTGRES_URI/dnim" "migrations/ensure_seeded.sql"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user