upgrade: fix scripts
This commit is contained in:
parent
e2469f577b
commit
9fe6bbdd5e
1 changed files with 82 additions and 70 deletions
|
|
@ -23,7 +23,7 @@ function merge_envs() {
|
|||
continue
|
||||
;;
|
||||
COMMON_PG_PASSWORD)
|
||||
pgpassword=$value
|
||||
pgpassword=$(echo $value | xargs)
|
||||
;;
|
||||
POSTGRES_VERSION | REDIS_VERSION | MINIO_VERSION)
|
||||
# Don't update db versions automatically.
|
||||
|
|
@ -50,7 +50,8 @@ function log_message() {
|
|||
|
||||
# Function to create migration versions based on the current and previous application versions
|
||||
function create_migration_versions() {
|
||||
cd "${SCHEMA_DIR:-/opt/openreplay/openreplay/scripts/schema}" || {
|
||||
SCHEMA_DIR="../schema/"
|
||||
cd $SCHEMA_DIR || {
|
||||
log_message "not able to cd $SCHEMA_DIR"
|
||||
exit 100
|
||||
}
|
||||
|
|
@ -85,10 +86,11 @@ function create_migration_versions() {
|
|||
echo "$joined_migration_versions"
|
||||
}
|
||||
|
||||
export SCHEMA_DIR="$(readlink -f ../schema/)"
|
||||
echo $SCHEMA_DIR
|
||||
# Function to perform migration
|
||||
function migrate() {
|
||||
# Set schema directory and previous application version
|
||||
export SCHEMA_DIR="../schema/"
|
||||
export PREVIOUS_APP_VERSION=${original_version#v}
|
||||
|
||||
# Create migration versions array
|
||||
|
|
@ -101,13 +103,23 @@ function migrate() {
|
|||
# Loop through versions and prepare Docker run commands
|
||||
for ver in "${joined_migration_versions[@]}"; do
|
||||
echo "$ver"
|
||||
"docker run --rm --network openreplay-net \
|
||||
--name pgmigrate -e 'PGHOST=postgres' -e 'PGPORT=5432' \
|
||||
-e 'PGDATABASE=postgres' -e 'PGUSER=postgres' -e 'PGPASSWORD=$pgpassword' \
|
||||
-v /opt/data/:$SCHEMA_DIR postgres psql -f /opt/data/schema/db/init_dbs/postgresql/$ver/$ver.sql"
|
||||
docker run --rm --network docker-compose_opereplay-net \
|
||||
--name pgmigrate -e PGHOST=postgres -e PGPORT=5432 \
|
||||
-e PGDATABASE=postgres -e PGUSER=postgres -e PGPASSWORD=$pgpassword \
|
||||
-v $SCHEMA_DIR:/opt/data/ postgres psql -f /opt/data/db/init_dbs/postgresql/$ver/$ver.sql
|
||||
done
|
||||
}
|
||||
|
||||
# Merge environment variables and perform migration
|
||||
merge_envs
|
||||
migrate
|
||||
|
||||
# Load variables from common.env into the current shell's environment
|
||||
set -a # automatically export all variables
|
||||
source common.env
|
||||
set +a
|
||||
|
||||
# Use the `envsubst` command to substitute the shell environment variables into reference_var.env and output to a combined .env
|
||||
find ./ -type f \( -iname "*.env" -o -iname "docker-compose.yaml" \) ! -name "common.env" -exec /bin/bash -c 'file="{}";cp "$file" "$file.bak"; envsubst < "$file.bak" > "$file"; rm "$file.bak"' \;
|
||||
|
||||
sudo -E docker-compose up -d
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue