FROM python:3.11-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

# Validate that migrations apply against a throwaway DB inside the image layer.
# At runtime the ./data volume shadows /app/data, so migrations are also run on
# startup (see CMD) to populate the mounted volume.
RUN alembic upgrade head

EXPOSE 8011

CMD ["sh", "-c", "python -m app.migration_bootstrap && alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8011"]
