diff --git a/.circleci/config.yml b/.circleci/config.yml index e11f4038c..76d319cc3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,6 +53,9 @@ jobs: - run: name: 'Check for banned C API usage' command: ci/banned.h.sh + - run: + name: 'Check for missing downgrade scripts' + command: ci/check_migration_files.sh check-sql-snapshots: docker: - image: 'citus/extbuilder:latest' diff --git a/ci/check_migration_files.sh b/ci/check_migration_files.sh new file mode 100755 index 000000000..eaaa6e96a --- /dev/null +++ b/ci/check_migration_files.sh @@ -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;