Auto-apply migrations on deploy (entrypoint + one-shot service) #23

Merged
justin merged 1 commits from deploy-auto-migrate into main 2026-06-07 10:54:32 -04:00
Owner

Backend entrypoint runs alembic upgrade head (RUN_MIGRATIONS=1) before uvicorn so a Watchtower image swap self-migrates; plus a one-shot migrate service for compose up. Idempotent + serialized so alembic never runs concurrently. Activating needs the updated compose on the host once.

Backend entrypoint runs alembic upgrade head (RUN_MIGRATIONS=1) before uvicorn so a Watchtower image swap self-migrates; plus a one-shot migrate service for compose up. Idempotent + serialized so alembic never runs concurrently. Activating needs the updated compose on the host once.
justin added 1 commit 2026-06-07 10:51:41 -04:00
So a deploy never needs a manual `alembic upgrade head`:

- Backend image gains an entrypoint that runs `alembic upgrade head` before
  uvicorn when RUN_MIGRATIONS=1 (set on the backend service). This self-migrates
  even on a Watchtower in-place image swap, which doesn't re-run one-shot jobs.
- A one-shot `migrate` service covers the `docker compose up` path; backend and
  worker depend on it completing, which also serializes it with the backend
  entrypoint so alembic never runs concurrently. `upgrade head` is idempotent.

Activating this needs the updated compose on the host once (Watchtower only
swaps images, not the compose file / env). After that, migrations are automatic.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
justin merged commit 9ee960c4ef into main 2026-06-07 10:54:32 -04:00
justin deleted branch deploy-auto-migrate 2026-06-07 10:54:32 -04:00
Sign in to join this conversation.