From d7f5b163592a261eb69fb09cb1a1404882ff9935 Mon Sep 17 00:00:00 2001 From: fawney19 Date: Tue, 23 Dec 2025 00:23:22 +0800 Subject: [PATCH] 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. --- deploy.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/deploy.sh b/deploy.sh index b4d5e58..b446a6e 100755 --- a/deploy.sh +++ b/deploy.sh @@ -179,7 +179,13 @@ else echo ">>> Dependencies unchanged." 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 echo ">>> App image not found, building..." build_app @@ -192,6 +198,10 @@ elif check_code_changed; then echo ">>> Code changed, rebuilding app image..." build_app NEED_RESTART=true +elif [ "$MIGRATION_CHANGED" = true ]; then + echo ">>> Migration files changed, rebuilding app image..." + build_app + NEED_RESTART=true else echo ">>> Code unchanged." fi @@ -204,9 +214,9 @@ else echo ">>> No changes detected, skipping restart." fi -# 检查迁移变化 -if check_migration_changed; then - echo ">>> Migration files changed, running database migration..." +# 检查迁移变化(如果前面已经检测到变化并重建了镜像,这里直接运行迁移) +if [ "$MIGRATION_CHANGED" = true ]; then + echo ">>> Running database migration..." sleep 3 run_migration else