Skip to content

feat: auto-run database migrations on container startup#8

Open
damienriehl wants to merge 1 commit intorelease/v0.2.0from
feat/auto-migrate-on-startup
Open

feat: auto-run database migrations on container startup#8
damienriehl wants to merge 1 commit intorelease/v0.2.0from
feat/auto-migrate-on-startup

Conversation

@damienriehl
Copy link
Contributor

Summary

  • Entrypoint script (scripts/entrypoint.sh): runs alembic upgrade head before starting the application, with a /tmp marker file to skip on uvicorn --reload re-invocations
  • Dockerfile: ENTRYPOINT delegates to entrypoint.sh, CMD remains uvicorn
  • compose.yaml: mount entrypoint script + set entrypoint/command so it works without rebuilding the image

Context

An 18MB OWL import was failing with "Could not reach the server" — root cause was a missing github_hook_id column (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 starts
  • Add a new migration, restart container — migration should apply automatically
  • File change triggers uvicorn reload — migration should NOT re-run (marker file)
  • Fresh docker compose up from rebuilt image — migrations run from ENTRYPOINT

🤖 Generated with Claude Code

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>
@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb9b8f1a-e000-42d0-b1f4-de08756dd541

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/auto-migrate-on-startup
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can customize the tone of the review comments and chat replies.

Configure the tone_instructions setting to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant