Skip to content

Commit

Permalink
Merge pull request #348 from jumpserver/pr@dev@perf_db_migrations
Browse files Browse the repository at this point in the history
perf: 优化初始化数据库逻辑
  • Loading branch information
wojiushixiaobai authored Sep 25, 2023
2 parents 6566c4f + f392645 commit d862cd3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion scripts/0_prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function prepare_image_files() {
fi

images=$(get_images)

for image in ${images}; do
echo "[${image}]"
pull_image "$image"
Expand Down
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 d862cd3

Please sign in to comment.