From 392418c3f9ba59872ec325207c76445faa71c37e Mon Sep 17 00:00:00 2001 From: sepehr Date: Sun, 17 May 2026 09:59:20 +0200 Subject: [PATCH] fix: run alembic migration in one-shot container before backend start - Use 'docker compose run --rm backend alembic upgrade head' to run migration in a throwaway container (doesn't need backend running) - Restore entrypoint migration fallback (don't block startup) - Restart backend after migration to pick up schema changes - Remove --no-cache (too slow, was causing timeouts) Co-Authored-By: Claude Opus 4.7 --- .gitea/workflows/deploy.yml | 11 +++++++---- docker/backend/entrypoint.sh | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 80bb681..fbaf0ce 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -29,8 +29,8 @@ jobs: git fetch origin production-deployment git reset --hard origin/production-deployment - echo "=== Building images (no cache) ===" - docker compose build --no-cache backend frontend + echo "=== Building images ===" + docker compose build backend frontend echo "=== Starting services ===" docker compose up -d --remove-orphans @@ -49,8 +49,11 @@ jobs: sleep 2 done - echo "=== Running database migrations ===" - docker compose exec -T backend alembic upgrade head + echo "=== Running database migrations (one-shot container) ===" + docker compose run --rm backend alembic upgrade head + + echo "=== Restarting backend to pick up migration ===" + docker compose restart backend echo "=== Waiting for backend healthy ===" for i in $(seq 1 20); do diff --git a/docker/backend/entrypoint.sh b/docker/backend/entrypoint.sh index fc46083..982245a 100644 --- a/docker/backend/entrypoint.sh +++ b/docker/backend/entrypoint.sh @@ -42,8 +42,7 @@ except: # Run database migrations echo "📦 Running database migrations..." - alembic upgrade head - echo "✅ Migrations applied successfully" + alembic upgrade head || echo "⚠️ Migration skipped (may already be up to date)" fi # Wait for Redis if configured