feat: auto-run database migrations on container startup#8
feat: auto-run database migrations on container startup#8damienriehl wants to merge 1 commit intorelease/v0.2.0from
Conversation
Add entrypoint script that runs `alembic upgrade head` before starting the application. Prevents schema drift when the API image or mounted code has new migrations but the database hasn't been migrated. - New scripts/entrypoint.sh: runs migrations then exec's CMD Uses /tmp marker to skip on uvicorn --reload re-invocations - Dockerfile: ENTRYPOINT delegates to entrypoint.sh - compose.yaml: mount entrypoint.sh + set entrypoint/command for dev Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can customize the tone of the review comments and chat replies.Configure the |
Summary
scripts/entrypoint.sh): runsalembic upgrade headbefore starting the application, with a/tmpmarker file to skip on uvicorn--reloadre-invocationsENTRYPOINTdelegates to entrypoint.sh,CMDremains uvicornentrypoint/commandso it works without rebuilding the imageContext
An 18MB OWL import was failing with "Could not reach the server" — root cause was a missing
github_hook_idcolumn (4 migrations behind). The unhandled 500 lacked CORS headers, causing the browser to treat it as a network error. This entrypoint prevents schema drift by auto-migrating on every container start.Test plan
docker compose up -d api— logs should show "Running database migrations..." once before uvicorn startsdocker compose upfrom rebuilt image — migrations run from ENTRYPOINT🤖 Generated with Claude Code