Conversation
The pg driver adapter's $connect() is lazy: it never proves the database is reachable, so the API reported "successfully started" and then 500'd every DB-backed request (login, the username check the create-account screen fires on open, the phone backfill) whenever Postgres was not up. PrismaService now forces a `SELECT 1` after connecting and waits for it, retrying while the database is still coming up (30 attempts, 2s apart). If it never answers within the budget it throws, so the process exits and pm2 restarts it instead of serving errors against a dead database. This makes cold boots deterministic once the DB exists rather than racing it. docker-compose gains a pg_isready healthcheck so `docker compose up -d --wait` can block until Postgres truly accepts connections, letting a deploy start the API only after the DB is ready. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe local Postgres container now reports readiness through a Docker healthcheck. PrismaService also verifies database availability during module startup, retrying ChangesDatabase readiness
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant DockerCompose
participant Postgres
participant PrismaService
participant Logger
DockerCompose->>Postgres: Run pg_isready healthcheck
Postgres-->>DockerCompose: Report readiness
PrismaService->>Postgres: Execute SELECT 1 during onModuleInit
Postgres-->>PrismaService: Return success or failure
PrismaService->>Logger: Log success or retry warning
PrismaService->>Postgres: Retry after 2 seconds when unavailable
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The pg driver adapter's $connect() is lazy: it never proves the database is reachable, so the API reported "successfully started" and then 500'd every DB-backed request (login, the username check the create-account screen fires on open, the phone backfill) whenever Postgres was not up.
PrismaService now forces a
SELECT 1after connecting and waits for it, retrying while the database is still coming up (30 attempts, 2s apart). If it never answers within the budget it throws, so the process exits and pm2 restarts it instead of serving errors against a dead database. This makes cold boots deterministic once the DB exists rather than racing it.docker-compose gains a pg_isready healthcheck so
docker compose up -d --waitcan block until Postgres truly accepts connections, letting a deploy start the API only after the DB is ready.Summary by CodeRabbit