db/scripts/gen_migrations.sh
Orion Kindel 508c1c2693
Some checks failed
gen-migrations / gen-migrations (push) Failing after 3s
fix: gen-migrations workflow
2023-07-18 22:11:47 -05:00

48 lines
1.1 KiB
Bash
Executable File

#! /bin/bash
set -e
source ./scripts/common.sh
revs=$(git log --format=%h | tac)
first_commit="7371374"
first_commit_n=$(echo "$revs" | grep -n "$first_commit" | awk -F: '{print $1}')
revs=$(echo "empty" && (echo "$revs" | tail --lines "+$first_commit_n"))
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="$?"
set -e
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
}
for i in $(seq 1 "$revs_ct"); do
do_i "$i"
done