Add CI job for checking missing downgrade scripts

migration-ci-script
Hanefi Önaldı 2020-06-24 13:09:31 +03:00
parent 50e115fe3a
commit 4b9d75c64c
No known key found for this signature in database
GPG Key ID: 45A2ACB84E394FBA
2 changed files with 32 additions and 0 deletions

View File

@ -53,6 +53,9 @@ jobs:
- run: - run:
name: 'Check for banned C API usage' name: 'Check for banned C API usage'
command: ci/banned.h.sh command: ci/banned.h.sh
- run:
name: 'Check for missing downgrade scripts'
command: ci/check_migration_files.sh
check-sql-snapshots: check-sql-snapshots:
docker: docker:
- image: 'citus/extbuilder:latest' - image: 'citus/extbuilder:latest'

29
ci/check_migration_files.sh Executable file
View File

@ -0,0 +1,29 @@
#! /bin/bash
set -euo pipefail
# This file checks for the existence of downgrade scripts for every upgrade script that is changed in the branch.
# list of migration files, and early exit if no migration scripts are touched
migration_files=$(git diff --name-only origin/master | grep "src/backend/distributed/sql/citus--.*sql") || exit 0
ret_value=0
for file in $migration_files
do
# There should always be 2 matches, and no need to avoid splitting here
# shellcheck disable=SC2207
versions=($(grep -Eo "\d\.\d-\d" <<< "$file"))
from_version=${versions[0]};
to_version=${versions[1]};
reverted_migration_file="src/backend/distributed/sql/citus--$to_version--$from_version.sql"
# check for the existence of reverted migration scripts
if [[ $(grep -xc reverted_migration_file <<< "$migration_files") == 0 ]]
then
echo "$file is updated, but $reverted_migration_file is missing in branch"
ret_value=1
fi
done
exit $ret_value;