chore: update migrations

This commit is contained in:
Orion Kindel 2023-07-18 22:06:57 -05:00
parent c32adb2107
commit 21957cf791
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719
6 changed files with 18 additions and 18 deletions

@ -1 +1 @@
Subproject commit 4bc2f54cfd2abdbf4a51d9648ec12ce80dd58ca5 Subproject commit f33340900061269c067e915082e827b07af1b8ad

View File

@ -63,11 +63,6 @@ create function public.usr_root()
language sql language sql
as $$select * from public.usr where tag = public.usr_tag_of_string('root')$$; 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() create function public.do_check_usr_tag()
returns trigger returns trigger
stable stable

View File

@ -7,9 +7,6 @@ create table public.grp
, tag public.grp_tag not null unique , tag public.grp_tag not null unique
); );
insert into public.grp (tag)
values (grp_tag_of_string('admins'));
create function public.grp_admins() create function public.grp_admins()
returns public.grp returns public.grp
stable stable

View File

@ -14,7 +14,7 @@ else
port=5432 port=5432
fi fi
docker compose down "$base_or_head" docker compose down "$base_or_head" &>/dev/null
url="postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$port" url="postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$port"
@ -25,28 +25,28 @@ isready() {
initdb() { initdb() {
dropdb=$(mktemp) dropdb=$(mktemp)
echo "drop database dnim with (force);" > "$dropdb" echo "drop database dnim with (force);" > "$dropdb"
psql --quiet "$url/postgres" -f "$dropdb" || true psql --quiet "$url/postgres" -f "$dropdb" &>/dev/null || true
psql --quiet "$url/postgres" -c "create database dnim" psql --quiet "$url/postgres" -c "create database dnim" &>/dev/null
} }
if [[ "$rev" = "empty" ]]; then if [[ "$rev" = "empty" ]]; then
docker compose up -d "$base_or_head" docker compose up -d "$base_or_head" &>/dev/null
isready isready
initdb initdb
exit 0 exit 0
fi fi
git worktree remove --force "./$base_or_head" || true git worktree remove --force "./$base_or_head" &>/dev/null || true
rm -rf "./$base_or_head" || true rm -rf "./$base_or_head" &>/dev/null || true
git worktree add "./$base_or_head" --detach "$rev" git worktree add "./$base_or_head" --detach "$rev" &>/dev/null
cp docker-compose.yml "./$base_or_head/docker-compose.yml" cp docker-compose.yml "./$base_or_head/docker-compose.yml"
cp .env.schema "./$base_or_head/.env.schema" cp .env.schema "./$base_or_head/.env.schema"
cd "./$base_or_head" cd "./$base_or_head"
docker compose up -d "$base_or_head" docker compose up -d "$base_or_head" &>/dev/null
cd "../$base_or_head" cd "../$base_or_head"
isready isready
initdb 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"

View File

@ -13,12 +13,15 @@ revs_ct=$(echo "$revs" | wc -l)
do_i() { do_i() {
base=$(echo "$revs" | tail --lines "+$1" | head -n 1) base=$(echo "$revs" | tail --lines "+$1" | head -n 1)
if [[ -f "./migrations/${base}_skipped.sql" ]]; then if [[ -f "./migrations/${base}_skipped.sql" ]]; then
echo "skip $base"
return return
fi fi
for j in $(seq "$(($1 + 1))" "$revs_ct"); do for j in $(seq "$(($1 + 1))" "$revs_ct"); do
head=$(echo "$revs" | tail --lines "+$j" | head -n 1) head=$(echo "$revs" | tail --lines "+$j" | head -n 1)
migration="./migrations/${base}_to_${head}.sql" migration="./migrations/${base}_to_${head}.sql"
echo "building $migration..."
set +e set +e
out=$(./scripts/diff.sh "$base" "$head") out=$(./scripts/diff.sh "$base" "$head")
status="$?" status="$?"
@ -26,12 +29,14 @@ do_i() {
if [[ "$status" = "1" && "$out" = *"head failed to build"* ]]; then if [[ "$status" = "1" && "$out" = *"head failed to build"* ]]; then
echo "" > "./migrations/${head}_skipped.sql" echo "" > "./migrations/${head}_skipped.sql"
echo "wrote ./migrations/${head}_skipped.sql"
continue continue
elif [[ "$status" = "1" ]]; then elif [[ "$status" = "1" ]]; then
echo out echo out
exit 1 exit 1
else else
echo "$out" > "$migration" echo "$out" > "$migration"
echo "wrote $migration"
break break
fi fi
done done

View File

@ -29,6 +29,7 @@ else
revs_to_run="$log" revs_to_run="$log"
if [[ "$rev_last" = "$rev_most_recent" ]]; then if [[ "$rev_last" = "$rev_most_recent" ]]; then
query_file "$POSTGRES_URI/dnim" "migrations/ensure_seeded.sql"
echo "all caught up! :)" echo "all caught up! :)"
exit 0 exit 0
elif [[ "$rev_last" != "empty" ]]; then elif [[ "$rev_last" != "empty" ]]; then
@ -57,4 +58,6 @@ else
exit 1 exit 1
fi fi
done; done;
query_file "$POSTGRES_URI/dnim" "migrations/ensure_seeded.sql"
fi fi