2023-07-19 02:31:56 +00:00
|
|
|
#! /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
|
2023-07-20 05:41:55 +00:00
|
|
|
echo "[$base]: skipped previously"
|
2023-07-19 02:31:56 +00:00
|
|
|
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"
|
2023-07-20 05:41:55 +00:00
|
|
|
|
|
|
|
if [[ -f "$migration" ]]; then
|
|
|
|
echo "[$migration]: exists"
|
2023-07-20 05:52:37 +00:00
|
|
|
break
|
2023-07-20 05:41:55 +00:00
|
|
|
else
|
|
|
|
echo "[$migration]: building..."
|
|
|
|
fi
|
2023-07-19 03:06:57 +00:00
|
|
|
|
2023-07-19 02:31:56 +00:00
|
|
|
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"
|
2023-07-20 05:41:55 +00:00
|
|
|
echo "[$migration]: skipped, $head bad"
|
2023-07-19 02:31:56 +00:00
|
|
|
continue
|
|
|
|
elif [[ "$status" = "1" ]]; then
|
2023-07-19 03:11:47 +00:00
|
|
|
echo "$out"
|
2023-07-19 02:31:56 +00:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "$out" > "$migration"
|
2023-07-20 05:41:55 +00:00
|
|
|
echo "[$migration]: wrote"
|
2023-07-19 02:31:56 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
for i in $(seq 1 "$revs_ct"); do
|
|
|
|
do_i "$i"
|
|
|
|
done
|