77 lines
2.1 KiB
Bash
Executable File
77 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT=${1:-$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)}
|
|
registry="$ROOT/priv/repo/migration_application_compatibility.tsv"
|
|
migrations_dir="$ROOT/priv/repo/migrations"
|
|
|
|
[[ -f "$registry" ]] || {
|
|
echo "Migration compatibility registry is missing: $registry" >&2
|
|
exit 2
|
|
}
|
|
|
|
[[ -d "$migrations_dir" ]] || {
|
|
echo "Migration directory is missing: $migrations_dir" >&2
|
|
exit 2
|
|
}
|
|
|
|
mapfile -t entries < <(
|
|
awk -F '\t' '
|
|
$0 !~ /^#/ && NF > 0 {
|
|
if (NF != 3 || $1 !~ /^[0-9]{14}$/ ||
|
|
($2 != "application_safe" && $2 != "forward_only") ||
|
|
$3 == "" || $3 == $2) {
|
|
print "INVALID\t" NR "\t" $0
|
|
} else {
|
|
print $1 "\t" $2 "\t" $3
|
|
}
|
|
}
|
|
' "$registry"
|
|
)
|
|
|
|
if [[ ${#entries[@]} -eq 0 ]]; then
|
|
echo "Migration compatibility registry has no reviewed entries." >&2
|
|
exit 2
|
|
fi
|
|
|
|
for entry in "${entries[@]}"; do
|
|
if [[ "$entry" == INVALID$'\t'* ]]; then
|
|
echo "Invalid migration registry entry: $entry" >&2
|
|
exit 2
|
|
fi
|
|
done
|
|
|
|
mapfile -t versions < <(printf '%s\n' "${entries[@]}" | cut -f1)
|
|
if [[ $(printf '%s\n' "${versions[@]}" | sort -u | wc -l) -ne ${#versions[@]} ]]; then
|
|
echo "Migration compatibility registry contains a duplicate version." >&2
|
|
exit 2
|
|
fi
|
|
|
|
first_reviewed_version=$(printf '%s\n' "${versions[@]}" | sort | head -n 1)
|
|
|
|
mapfile -t reviewed_migrations < <(
|
|
find "$migrations_dir" -maxdepth 1 -type f -name '[0-9]*.exs' -printf '%f\n' |
|
|
awk -F_ -v first="$first_reviewed_version" '$1 >= first {print $1}' |
|
|
sort
|
|
)
|
|
|
|
for version in "${versions[@]}"; do
|
|
mapfile -t files < <(
|
|
find "$migrations_dir" -maxdepth 1 -type f -name "${version}_*.exs" -printf '%f\n'
|
|
)
|
|
if [[ ${#files[@]} -ne 1 ]]; then
|
|
echo "Registry version $version must identify exactly one migration file." >&2
|
|
exit 2
|
|
fi
|
|
done
|
|
|
|
for version in "${reviewed_migrations[@]}"; do
|
|
matches=$(printf '%s\n' "${versions[@]}" | grep -Fxc "$version" || true)
|
|
if [[ "$matches" -ne 1 ]]; then
|
|
echo "Migration $version must have exactly one reviewed registry entry." >&2
|
|
exit 2
|
|
fi
|
|
done
|
|
|
|
echo "Migration compatibility registry is complete and internally consistent."
|