From 09dd6580d2b6719dd5e1cbc7ac3ef52ce1a8c471 Mon Sep 17 00:00:00 2001 From: Weimin Yu Date: Mon, 31 Aug 2020 15:08:37 -0400 Subject: [PATCH] Cover more base in forbidden SQL change check (#785) * Cover more base in forbidden SQL change check Update the forbidden SQL change detection script to include file deletion and renaming as well as edits. --- integration/run_schema_check.sh | 16 +++++++++++----- integration/testutils_bashrc | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/integration/run_schema_check.sh b/integration/run_schema_check.sh index ce37eaab8..5b9ba4584 100755 --- a/integration/run_schema_check.sh +++ b/integration/run_schema_check.sh @@ -26,9 +26,14 @@ Checks for post-deployment change to Flyway scripts. With Flyway, once an incremental change script is deployed, it must not be changed. Even changes to comments or whitespaces would cause validation -failures during future deployment. This script checks for changes to scripts -that have already been deployed to Sandbox. The assumption is that the schema -in Sandbox is always newer than that in production. +failures during future deployment. This script checks for changes (including +removal and renaming which may happen due to incorrect merge conflict +resolution) to scripts that have already been deployed to Sandbox. The +assumption is that the schema in Sandbox is always newer than that in +production. + +A side-effect of this check is that old branches missing recently deployed +scripts must update first. Options: -h, --help show this help text @@ -61,7 +66,7 @@ fi sandbox_tag=$(fetchVersion sql sandbox ${DEV_PROJECT}) echo "Checking Flyway scripts against schema in Sandbox (${sandbox_tag})." modified_sqls=$(git diff --name-status ${sandbox_tag} \ - db/src/main/resources/sql/flyway | grep ^M | grep \.sql$ | wc -l) + db/src/main/resources/sql/flyway | grep "^M\|^D\|^R" | grep \.sql$ | wc -l) if [[ ${modified_sqls} = 0 ]]; then echo "No illegal change to deployed schema scripts." @@ -69,6 +74,7 @@ if [[ ${modified_sqls} = 0 ]]; then else echo "Changes to the following files are not allowed:" echo $(git diff --name-status ${sandbox_tag} \ - db/src/main/resources/sql/flyway | grep ^M | grep \.sql$) + db/src/main/resources/sql/flyway | grep "^M\|^D\|^R" | grep \.sql$) + echo "Make sure your branch is up to date with HEAD of master." exit 1 fi diff --git a/integration/testutils_bashrc b/integration/testutils_bashrc index 8fd92370c..572fbd865 100644 --- a/integration/testutils_bashrc +++ b/integration/testutils_bashrc @@ -15,7 +15,8 @@ # This file declares shell functions used by other scripts in this folder. # Fetch the tag of the currently deployed release of Nomulus server -# or SQL schema. +# or SQL schema. The caller is responsible for fetching relevant git +# tags to the local repo. function fetchVersion() { local deployed_system=${1} local env=${2}