status-go/_assets/scripts/migration_check.sh

49 lines
1.5 KiB
Bash
Raw Permalink 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
}
2024-03-06 20:24:19 +00:00
git checkout origin/develop
git pull origin develop
git checkout -
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")
2024-03-06 20:24:19 +00:00
# protocol migrations
check_migration_order $all_files
committed_files=$(git ls-tree -r --name-only HEAD appdatabase/migrations/sql/*.sql | sort)
staged_files=$(git diff --name-only origin/develop appdatabase/migrations/sql/*.sql | sort)
all_files=$(echo -e "$committed_files\n$staged_files")
# account migrations
check_migration_order $all_files
committed_files=$(git ls-tree -r --name-only HEAD protocol/encryption/migrations/sqlite/*.sql | sort)
staged_files=$(git diff --name-only origin/develop protocol/encryption/migrations/sqlite/*.sql | sort)
all_files=$(echo -e "$committed_files\n$staged_files")
# encryption migrations
2023-06-21 12:21:26 +00:00
check_migration_order $all_files
exit 0