fix: rebuild app image when migration files change

deploy.sh was only running alembic upgrade on the old container when
migration files changed, but the migration files are baked into the
Docker image. Now it rebuilds the app image when migrations change.
This commit is contained in:
fawney19
2025-12-23 00:23:22 +08:00
parent 7185818724
commit d7f5b16359

View File

@@ -179,7 +179,13 @@ else
echo ">>> Dependencies unchanged." echo ">>> Dependencies unchanged."
fi fi
# 检查代码是否变化,或者 base 重建了app 依赖 base # 检查代码或迁移是否变化,或者 base 重建了app 依赖 base
# 注意:迁移文件打包在镜像中,所以迁移变化也需要重建 app 镜像
MIGRATION_CHANGED=false
if check_migration_changed; then
MIGRATION_CHANGED=true
fi
if ! docker image inspect aether-app:latest >/dev/null 2>&1; then if ! docker image inspect aether-app:latest >/dev/null 2>&1; then
echo ">>> App image not found, building..." echo ">>> App image not found, building..."
build_app build_app
@@ -192,6 +198,10 @@ elif check_code_changed; then
echo ">>> Code changed, rebuilding app image..." echo ">>> Code changed, rebuilding app image..."
build_app build_app
NEED_RESTART=true NEED_RESTART=true
elif [ "$MIGRATION_CHANGED" = true ]; then
echo ">>> Migration files changed, rebuilding app image..."
build_app
NEED_RESTART=true
else else
echo ">>> Code unchanged." echo ">>> Code unchanged."
fi fi
@@ -204,9 +214,9 @@ else
echo ">>> No changes detected, skipping restart." echo ">>> No changes detected, skipping restart."
fi fi
# 检查迁移变化 # 检查迁移变化(如果前面已经检测到变化并重建了镜像,这里直接运行迁移)
if check_migration_changed; then if [ "$MIGRATION_CHANGED" = true ]; then
echo ">>> Migration files changed, running database migration..." echo ">>> Running database migration..."
sleep 3 sleep 3
run_migration run_migration
else else