fix(migrate): Race condition on version check
Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com>
This commit is contained in:
parent
e3589a01f5
commit
b802b94081
1 changed files with 56 additions and 52 deletions
|
|
@ -5,9 +5,9 @@ cd $(dirname $0)
|
||||||
|
|
||||||
is_migrate=$1
|
is_migrate=$1
|
||||||
|
|
||||||
# Converting alphaneumeric to number.
|
# Passed from env
|
||||||
PREVIOUS_APP_VERSION=`echo $PREVIOUS_APP_VERSION | cut -d "v" -f2`
|
# PREVIOUS_APP_VERSION
|
||||||
CHART_APP_VERSION=`echo $CHART_APP_VERSION | cut -d "v" -f2`
|
# CHART_APP_VERSION
|
||||||
|
|
||||||
function migration() {
|
function migration() {
|
||||||
ls -la /opt/openreplay/openreplay
|
ls -la /opt/openreplay/openreplay
|
||||||
|
|
@ -36,54 +36,58 @@ function migration() {
|
||||||
|
|
||||||
# We need to remove version dots
|
# We need to remove version dots
|
||||||
function normalise_version {
|
function normalise_version {
|
||||||
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
|
version=$1
|
||||||
|
echo $(echo ${version:1} | tr -d '.')
|
||||||
}
|
}
|
||||||
all_versions=(`ls -l db/init_dbs/$db | grep -E ^d | grep -v create | awk '{print $NF}'`)
|
all_versions=($(ls -l db/init_dbs/$db | grep -E ^d | grep -v create | awk '{print $NF}'))
|
||||||
migration_versions=(`for ver in ${all_versions[*]}; do if [[ $(normalise_version $ver) > $(normalise_version "${PREVIOUS_APP_VERSION}") ]]; then echo $ver; fi; done | sort -V`)
|
migration_versions=($(for ver in ${all_versions[*]}; do if [[ $(normalise_version $ver) > $(normalise_version "${PREVIOUS_APP_VERSION}") ]]; then echo $ver; fi; done | sort -V))
|
||||||
echo "Migration version: ${migration_versions[*]}"
|
echo "Migration version: ${migration_versions[*]}"
|
||||||
# Can't pass the space seperated array to ansible for migration. So joining them with ,
|
# Can't pass the space seperated array to ansible for migration. So joining them with ,
|
||||||
joined_migration_versions=$(IFS=, ; echo "${migration_versions[*]}")
|
joined_migration_versions=$(
|
||||||
|
IFS=,
|
||||||
|
echo "${migration_versions[*]}"
|
||||||
|
)
|
||||||
|
|
||||||
cd -
|
cd -
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
postgresql)
|
postgresql)
|
||||||
/bin/bash postgresql.sh migrate $joined_migration_versions
|
/bin/bash postgresql.sh migrate $joined_migration_versions
|
||||||
;;
|
;;
|
||||||
minio)
|
minio)
|
||||||
/bin/bash minio.sh migrate $joined_migration_versions
|
/bin/bash minio.sh migrate $joined_migration_versions
|
||||||
;;
|
;;
|
||||||
clickhouse)
|
clickhouse)
|
||||||
/bin/bash clickhouse.sh migrate $joined_migration_versions
|
/bin/bash clickhouse.sh migrate $joined_migration_versions
|
||||||
;;
|
;;
|
||||||
kafka)
|
kafka)
|
||||||
/bin/bash kafka.sh migrate $joined_migration_versions
|
/bin/bash kafka.sh migrate $joined_migration_versions
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown operation for db migration; exiting."
|
echo "Unknown operation for db migration; exiting."
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(){
|
function init() {
|
||||||
case $1 in
|
case $1 in
|
||||||
postgresql)
|
postgresql)
|
||||||
/bin/bash postgresql.sh init
|
/bin/bash postgresql.sh init
|
||||||
;;
|
;;
|
||||||
minio)
|
minio)
|
||||||
/bin/bash minio.sh migrate $migration_versions
|
/bin/bash minio.sh migrate $migration_versions
|
||||||
;;
|
;;
|
||||||
clickhouse)
|
clickhouse)
|
||||||
/bin/bash clickhouse.sh init
|
/bin/bash clickhouse.sh init
|
||||||
;;
|
;;
|
||||||
kafka)
|
kafka)
|
||||||
/bin/bash kafka.sh init
|
/bin/bash kafka.sh init
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown operation for db init; exiting."
|
echo "Unknown operation for db init; exiting."
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
@ -94,14 +98,14 @@ fi
|
||||||
|
|
||||||
# dbops.sh true(upgrade) clickhouse
|
# dbops.sh true(upgrade) clickhouse
|
||||||
case "$is_migrate" in
|
case "$is_migrate" in
|
||||||
"false")
|
"false")
|
||||||
init $2
|
init $2
|
||||||
;;
|
;;
|
||||||
"true")
|
"true")
|
||||||
migration $2
|
migration $2
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown operation for db migration; exiting."
|
echo "Unknown operation for db migration; exiting."
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue