Files
provenance/backend/docker-entrypoint.sh
justin 7f640649b9 Auto-apply migrations on deploy (entrypoint + one-shot service)
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>
2026-06-07 10:50:28 -04:00

15 lines
548 B
Bash

#!/bin/sh
# Container entrypoint. When RUN_MIGRATIONS=1 (set on the backend service),
# apply DB migrations before handing off to the command. This makes a deploy
# self-migrating even when images are swapped in place (e.g. by Watchtower),
# without a separate orchestration step. `alembic upgrade head` is idempotent —
# a no-op when the schema is already current.
set -e
if [ "${RUN_MIGRATIONS:-0}" = "1" ]; then
echo "[entrypoint] applying database migrations (alembic upgrade head)…"
uv run --no-dev alembic upgrade head
fi
exec "$@"