From 70f95e9f5c9eb133ad04a3bd186142489df36c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9A=E9=80=9A?= Date: Sun, 29 Mar 2026 13:04:08 +0800 Subject: [PATCH] =?UTF-8?q?deploy.sh=E5=A2=9E=E5=8A=A0=E8=A1=A8=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=B8=80=E8=87=B4=E6=80=A7=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index 4bfb307a..a431f377 100755 --- a/deploy.sh +++ b/deploy.sh @@ -63,9 +63,19 @@ $DC_CMD up -d --build echo "🗄️ 执行数据库表结构更新..." $DC_CMD exec -T hxops-backend flask --app manage.py db upgrade || { echo "❌ 数据库迁移失败"; exit 1; } +# 5.1 SQLAlchemy 兜底同步(补齐缺失表,不替代 Alembic 迁移) +echo "🧩 执行 SQLAlchemy 表结构兜底同步..." +$DC_CMD exec -T hxops-backend python - <<'PY' || { echo "❌ SQLAlchemy 表结构同步失败"; exit 1; } +from app import create_app, db + +app = create_app('production') +with app.app_context(): + db.create_all() +print("SQLAlchemy create_all completed.") +PY + # 6. 清理未使用镜像 echo "🧹 清理旧镜像..." docker image prune -f echo "✅ 部署完成!" -