diff --git a/install.sh b/install.sh index df91759..91dc1b9 100644 --- a/install.sh +++ b/install.sh @@ -725,15 +725,33 @@ if [[ $PG_HOST == postgres ]]; then fi progress '初始化数据库结构' printf '正在初始化数据库,请稍候...\n' +run_migration() { + local migration_log migration_rc + migration_log=$(mktemp "$INSTALL_TMP_DIR/migration.XXXXXX.log") || die '无法创建数据库迁移日志' + chmod 600 "$migration_log" + if (( EXISTING_DB )); then + export XYMEDIA_EXTERNAL_MIGRATION_CONFIRM=YES + if "${COMPOSE[@]}" --profile migration --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" "${COMPOSE_FUSE[@]}" run --rm -T --no-deps app-migrate migrate --config /app/config.yaml >"$migration_log" 2>&1; then + migration_rc=0 + else + migration_rc=$? + fi + else + if "${COMPOSE[@]}" --profile migration --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" "${COMPOSE_FUSE[@]}" run --rm -T --no-deps app-migrate migrate --new --config /app/config.yaml >"$migration_log" 2>&1; then + migration_rc=0 + else + migration_rc=$? + fi + fi + cat "$migration_log" + cat "$migration_log" >>"$INSTALL_LOG" + printf '数据库迁移退出码:%s\n' "$migration_rc" + printf '数据库迁移退出码:%s\n' "$migration_rc" >>"$INSTALL_LOG" + return "$migration_rc" +} set +e -if (( EXISTING_DB )); then - export XYMEDIA_EXTERNAL_MIGRATION_CONFIRM=YES - run_visible_logged "${COMPOSE[@]}" --profile migration --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" "${COMPOSE_FUSE[@]}" run --rm -T --no-deps app-migrate migrate --config /app/config.yaml - migration_rc=$? -else - run_visible_logged "${COMPOSE[@]}" --profile migration --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" "${COMPOSE_FUSE[@]}" run --rm -T --no-deps app-migrate migrate --new --config /app/config.yaml - migration_rc=$? -fi +run_migration +migration_rc=$? set -e if (( migration_rc != 0 )); then persist_installer_log