fix(deploy): 全新部署链路健壮性(0004 幂等 + 迁移前置 + 空库守卫)
AIOps CI / Backend (test, vet, build) (push) Canceled after 0s
AIOps CI / Agent (test, vet, build) (push) Canceled after 0s
AIOps CI / Frontend (typecheck, lint, build) (push) Canceled after 0s
AIOps CI / API integration (SQLite + redka) (push) Canceled after 0s

- 0004_metric_aggregate_unique 改为幂等:新库基线已由模型 uniqueIndex 建出
  uniq_metric_agg,再次 CREATE 会以 1061 重复键名中断 migrate up,
  导致 0005_agent_settings 建不出来(全新部署实测复现)
- 新增 database.IndexExists:跨 SQLite/MySQL/PostgreSQL 判断索引是否存在
- 新增 database.EnsureSchemaInitialized:服务启动遇到空库时明确失败并给出
  执行 aiops migrate up 的指引,避免「服务起来了但页面全是空数据」
- run.sh docker up/upgrade/update 先跑一次 aiops migrate up 再启动服务

// Logan.Li
This commit is contained in:
Logan.Li committed 2026-09-14 09:02:42 +00:00
1 parent 7a96381dc7
commit f3a4fb569f
5 files changed
+57

No files matched your search

+7
View File
@@ -759,6 +759,13 @@ cmd_docker() {
case "$action" in
up|upgrade|update)
banner "========== Docker Compose 启动/升级 ($BUILD_VERSION) =========="
# 全新部署时库是空的(服务启动刻意不建表),先显式跑一次结构迁移再启动服务,
# 避免容器先起来面对空库;已初始化的库此步幂等,只会输出「迁移已是最新状态」。 // Logan.Li
info "数据库结构迁移 (aiops migrate up)..."
if ! $DOCKER_COMPOSE run --rm --build aiops ./aiops migrate up; then
error "数据库迁移失败:请检查上方输出(历史库缺少迁移记录时需先执行 aiops migrate baseline)"
exit 1
fi
# Docker 在容器内构建,无需清理宿主机产物;每次 prune 缓存会导致下次全量编译 // Logan.Li
if [ "$fresh_build" -eq 1 ]; then
info "全量重建镜像 (--no-cache)..."