This is an automated email from the ASF dual-hosted git repository.
rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 760e6d0 TO DB Tests: Always run db downgrades (#6351)
760e6d0 is described below
commit 760e6d0c9602d4a5c372ec73d14d2461066fae9b
Author: Zach Hoffman <[email protected]>
AuthorDate: Mon Nov 15 19:59:07 2021 +0000
TO DB Tests: Always run db downgrades (#6351)
* Use tabs for tabbing
* TO DB Tests: Always run db downgrades
---
traffic_ops_db/test/docker/run-db-test.sh | 77 +++++++++++++------------------
1 file changed, 31 insertions(+), 46 deletions(-)
diff --git a/traffic_ops_db/test/docker/run-db-test.sh
b/traffic_ops_db/test/docker/run-db-test.sh
index befdde1..30e8184 100755
--- a/traffic_ops_db/test/docker/run-db-test.sh
+++ b/traffic_ops_db/test/docker/run-db-test.sh
@@ -38,13 +38,13 @@ postgresql_package="$(<<<"postgresql${POSTGRES_VERSION}"
sed 's/\.//g' |
)"
pg_isready=$(rpm -ql "$postgresql_package" | grep bin/pg_isready)
if [[ ! -x "$pg_isready" ]] ; then
- echo "Can't find pg_ready in ${postgresql_package}"
- exit 1
+ echo "Can't find pg_ready in ${postgresql_package}"
+ exit 1
fi
while ! $pg_isready -h"$DB_SERVER" -p"$DB_PORT" -d "$DB_NAME"; do
- echo "waiting for db on $DB_SERVER $DB_PORT"
- sleep 3
+ echo "waiting for db on $DB_SERVER $DB_PORT"
+ sleep 3
done
echo "*:*:*:postgres:$DB_USER_PASS" > "${HOME}/.pgpass"
@@ -58,29 +58,29 @@ export GOPATH=/opt/traffic_ops/go
# gets the current DB version. On success, output the version number. On
failure, output a failure message starting with 'failed'.
get_current_db_version() {
- local dbversion_output
- if ! dbversion_output="$(./db/admin --env=production dbversion 2>&1)"; then
- echo "failed to get dbversion: $dbversion_output"
- return
- fi
- local version=$(echo "$dbversion_output" | egrep '^dbversion
[[:digit:]]+$' | awk '{print $2}')
- if [[ -z "$version" ]]; then
- echo "failed to get dbversion from output: $db_version_output"
- return
- fi
- echo "$version"
+ local dbversion_output
+ if ! dbversion_output="$(./db/admin --env=production dbversion 2>&1)";
then
+ echo "failed to get dbversion: $dbversion_output"
+ return
+ fi
+ local version=$(echo "$dbversion_output" | egrep '^dbversion
[[:digit:]]+$' | awk '{print $2}')
+ if [[ -z "$version" ]]; then
+ echo "failed to get dbversion from output: $db_version_output"
+ return
+ fi
+ echo "$version"
}
get_db_dumps() {
- find /db_dumps -name '*.dump'
+ find /db_dumps -name '*.dump'
}
db_is_empty=true
for d in $(get_db_dumps); do
- db_is_empty=false
- echo "checking integrity of DB dump: $d"
- pg_restore -l "$d" > /dev/null || { echo "invalid DB dump: $d. Unable to
list contents"; exit 1; }
+ db_is_empty=false
+ echo "checking integrity of DB dump: $d"
+ pg_restore -l "$d" > /dev/null || { echo "invalid DB dump: $d. Unable
to list contents"; exit 1; }
done
cd "$TO_DIR"
@@ -93,8 +93,8 @@ fi
# reset the DB if it is empty (i.e. no db.dump was provided)
if [[ "$old_db_version" -eq 0 ]]; then
- db_is_empty=true
- ./db/admin --env=production reset || { echo "DB reset failed!"; exit 1; }
+ db_is_empty=true
+ ./db/admin --env=production reset || { echo "DB reset failed!"; exit 1;
}
fi
# applies migrations then performs seeding and patching
@@ -103,32 +103,17 @@ fi
new_db_version=$(get_current_db_version)
[[ "$new_db_version" =~ ^failed ]] && { echo "get_current_db_version failed:
$new_db_version"; exit 1; }
-run_db_downgrades=true
-
-if [[ "$old_db_version" = "$new_db_version" ]]; then
- echo "new DB version matches old DB version, no downgrade migrations to
test"
- run_db_downgrades=false
-fi
-
-if [[ "$db_is_empty" = true ]]; then
- echo "starting DB was empty, skipping DB downgrades"
- run_db_downgrades=false
-fi
-
-if [[ "$run_db_downgrades" = true ]]; then
- # downgrade the DB until the initial DB version
- while [[ "$new_db_version" != "$old_db_version" ]]; do
- ./db/admin --env=production down || { echo "DB downgrade failed!";
exit 1; }
- new_db_version=$(get_current_db_version)
- [[ "$new_db_version" =~ ^failed ]] && { echo "get_current_db_version
failed: $new_db_version"; exit 1; }
- done
-fi
+# downgrade the DB until the initial DB version
+while [[ "$new_db_version" != "$old_db_version" ]]; do
+ ./db/admin --env=production down || { echo "DB downgrade failed!"; exit
1; }
+ new_db_version=$(get_current_db_version)
+ [[ "$new_db_version" =~ ^failed ]] && { echo "get_current_db_version
failed: $new_db_version"; exit 1; }
+done
# test full restoration of the initial DB dump
for d in $(get_db_dumps); do
- echo "testing restoration of DB dump: $d"
- dropdb --echo --if-exists "$DB_NAME" < "$d" > /dev/null || echo "Dropping
DB ${DB_NAME} failed: $d"
- createdb --echo < "$d" > /dev/null || echo "Creating DB ${DB_NAME} failed:
$d"
- pg_restore --verbose --clean --if-exists --exit-on-error -d "$DB_NAME" <
"$d" > /dev/null || { echo "DB restoration failed: $d"; exit 1; }
+ echo "testing restoration of DB dump: $d"
+ dropdb --echo --if-exists "$DB_NAME" < "$d" > /dev/null || echo
"Dropping DB ${DB_NAME} failed: $d"
+ createdb --echo < "$d" > /dev/null || echo "Creating DB ${DB_NAME}
failed: $d"
+ pg_restore --verbose --clean --if-exists --exit-on-error -d "$DB_NAME"
< "$d" > /dev/null || { echo "DB restoration failed: $d"; exit 1; }
done
-