Skip to content

Commit

Permalink
perf: 优化初始化数据库逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
wojiushixiaobai committed Sep 22, 2023
1 parent bcfa942 commit 49ed535
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,9 @@ function get_db_migrate_compose_cmd() {

function create_db_ops_env() {
cmd=$(get_db_migrate_compose_cmd)
${cmd} up -d
${cmd} up -d || {
exit 1
}
}

function down_db_ops_env() {
Expand All @@ -552,31 +554,25 @@ function down_db_ops_env() {
}

function perform_db_migrations() {
if ! create_db_ops_env; then
mysql_host=$(get_config DB_HOST)
redis_host=$(get_config REDIS_HOST)
if [[ "${mysql_host}" == "mysql" ]]; then
while [[ "$(docker inspect -f "{{.State.Health.Status}}" jms_mysql)" != "healthy" ]]; do
sleep 5s
done
fi
if [[ "${redis_host}" == "redis" ]]; then
while [[ "$(docker inspect -f "{{.State.Health.Status}}" jms_redis)" != "healthy" ]]; do
sleep 5s
done
fi
create_db_ops_env
sleep 5s
fi
mysql_host=$(get_config DB_HOST)
redis_host=$(get_config REDIS_HOST)

docker exec -i jms_core bash -c './jms upgrade_db'
ret=$?
create_db_ops_env
if [[ "${mysql_host}" == "mysql" ]]; then
while [[ "$(docker inspect -f "{{.State.Health.Status}}" jms_mysql)" != "healthy" ]]; do
sleep 5s
done
fi
if [[ "${redis_host}" == "redis" ]]; then
while [[ "$(docker inspect -f "{{.State.Health.Status}}" jms_redis)" != "healthy" ]]; do
sleep 5s
done
fi

down_db_ops_env
if [[ "$ret" != "0" ]]; then
docker exec -i jms_core bash -c './jms upgrade_db' || {
log_error "$(gettext 'Failed to change the table structure')!"
exit 1
fi
}
}

function set_current_version() {
Expand Down

0 comments on commit 49ed535

Please sign in to comment.