From f8bd064f652e99307a1f1bde10f4cce3d2ae05a5 Mon Sep 17 00:00:00 2001 From: chris-bellingham Date: Fri, 31 Jan 2025 11:40:40 +0000 Subject: [PATCH] Add DETS migration script --- bin/migrate-dets.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 bin/migrate-dets.sh diff --git a/bin/migrate-dets.sh b/bin/migrate-dets.sh new file mode 100755 index 00000000000..d9113e0cf60 --- /dev/null +++ b/bin/migrate-dets.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# This script is a wrapper around various flyway gradle tasks, and can be used to perform data migration against a named database in DETS. +# The script requires the environment variables FLYWAY_USER and FLYWAY_PASSWORD to be set, and the executed tasks take their configuration from the flyway{} +# block in the build.gradle file located in the project root. + +set -euo pipefail + +if [ -z "${FLYWAY_USER:-}" ]; then + echo "Env var FLYWAY_USER must be set" + exit 1 +fi + +if [ -z "${FLYWAY_PASSWORD:-}" ]; then + echo "Env var FLYWAY_PASSWORD must be set" + exit 1 +fi + +DATABASE_NAME=${1:-} +if [ -z "$DATABASE_NAME" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Port 5433 is the local port that is mapped to the DB on the production bastion, per +# https://tools.hmcts.net/confluence/display/DMP/Applying+Flyway+changes+to+Migration +export FLYWAY_URL="jdbc:postgresql://localhost:5433/$DATABASE_NAME" + +cd .. +./gradlew flywayInfo + +read -p 'Execute flywayMigrate? (y/n): ' continue +if [ "$continue" != "y" ] +then + exit 1 +fi + +./gradlew flywayMigrate +./gradlew flywayValidate +./gradlew flywayInfo