From caa5c995854c59208e3aa0c611fcccf76ebe72aa Mon Sep 17 00:00:00 2001 From: aswin Date: Mon, 29 Jun 2026 13:02:11 +0530 Subject: [PATCH] Run Alembic migrations on container boot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The image shipped without alembic/ or alembic.ini and booted straight into uvicorn, so migrations never ran. Fresh volumes survived via create_all, but any existing deploy drifted on schema changes — e.g. POST /batches 500'd with "column monthly_fee does not exist" after the dues/fee PR. Copy alembic into the image and `alembic upgrade head` before uvicorn. Both revisions are idempotent (0001 = create_all, 0002 = guarded add), so it's safe on fresh and stale DBs alike. Co-Authored-By: Claude Opus 4.8 --- Dockerfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index be9ba38..9525f05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,11 @@ WORKDIR /app COPY backend/requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY backend/app ./app +COPY backend/alembic ./alembic +COPY backend/alembic.ini ./alembic.ini COPY --from=build /fe/dist ./app/static EXPOSE 8000 -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] +# Apply migrations before boot. Both revisions are idempotent (0001 = create_all, +# 0002 = guarded add), so this is safe on a fresh DB and fixes a stale one. +CMD ["sh", "-c", "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000"]