status-go/_assets/scripts/migration_check.sh

31 lines
835 B
Bash
Raw Normal View History

#!/usr/bin/env bash
2023-06-21 12:21:26 +00:00
set -e
set -o pipefail
check_migration_order() {
local prev_migration=""
for file in "$@"; do
current_migration=$(echo "$file" | cut -d'-' -f1)
if [[ ! -z "$prev_migration" && "$current_migration" < "$prev_migration" ]]; then
echo "migration ${current_migration} is not in order with ${prev_migration}"
echo "Error: Migration files are out of order. Please ensure migrations are added in chronological order."
exit 1
fi
prev_migration="$current_migration"
done
}
2023-06-28 08:49:24 +00:00
git fetch origin develop
2023-06-21 12:21:26 +00:00
committed_files=$(git ls-tree -r --name-only HEAD protocol/migrations/sqlite/*.sql | sort)
staged_files=$(git diff --name-only origin/develop protocol/migrations/sqlite/*.sql | sort)
all_files=$(echo -e "$committed_files\n$staged_files")
check_migration_order $all_files
exit 0