Skip to content
This repository was archived by the owner on Feb 15, 2026. It is now read-only.

fix: add database connection pool configuration#15

Open
NicolasRitouet wants to merge 2 commits into
mainfrom
fix/db-connection-pooling
Open

fix: add database connection pool configuration#15
NicolasRitouet wants to merge 2 commits into
mainfrom
fix/db-connection-pooling

Conversation

@NicolasRitouet
Copy link
Copy Markdown
Member

@NicolasRitouet NicolasRitouet commented Feb 6, 2026

Summary

  • Configure postgres.js pool: max: 20, idle_timeout: 20s, connect_timeout: 10s
  • Pool size configurable via DB_POOL_MAX env var
  • Previous defaults had no idle cleanup (idle_timeout: 0), which could leak connections under sustained load

Test plan

  • Type-check passes
  • All 923 tests pass
  • Monitor connection count in production after deploy

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Optimized database connection pooling and timeouts to improve stability and performance under load.
  • New Features
    • Made database schema utilities publicly available for easier access and integration.

Configure postgres.js pool with max connections (20, configurable via
DB_POOL_MAX), idle timeout (20s), and connect timeout (10s). Defaults
had no idle cleanup which could leak connections under load.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

The Postgres client initialization in the database module now includes a pool configuration object (max from DB_POOL_MAX, idle_timeout, connect_timeout). The module also re-exports everything from ./schema.

Changes

Cohort / File(s) Summary
Database Client Configuration
src/db/index.ts
Replaced plain Postgres connection with postgres(connectionString, { max, idle_timeout, connect_timeout }) where max derives from DB_POOL_MAX (default 20), idle_timeout set to 20, and connect_timeout set to 10. Added export * from "./schema".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I tuned the pool, set timeouts neat,

Connections hop on nimble feet.
Schemas waved, now shared with pride,
Gardens of data open wide.
— a rabbit's code-bound stride 🥕🐇

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding database connection pool configuration to improve connection management.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/db-connection-pooling

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/db/index.ts`:
- Around line 15-20: The current postgres pool config uses
parseInt(process.env.DB_POOL_MAX || "20") which can yield NaN for non-numeric
env values; update the logic around sql creation to validate and default
DB_POOL_MAX: parse DB_POOL_MAX with a radix, check Number.isFinite and >0, and
fall back to 20 when invalid, then pass that validated numeric value to the max
option in the postgres(...) call (refer to the sql export and the parseInt usage
for where to change).
🧹 Nitpick comments (1)
src/db/index.ts (1)

16-20: Consider making idle_timeout and connect_timeout configurable too, or document the hardcoded values.

max is configurable via an env var but idle_timeout (20s) and connect_timeout (10s) are hardcoded. These may need tuning per environment (e.g., a longer connect timeout behind a VPN/proxy, or a shorter idle timeout in serverless). Even if you keep defaults, adding env var overrides would be consistent with the DB_POOL_MAX pattern.

Comment thread src/db/index.ts
Use Number.isFinite() check to handle empty string, non-numeric,
or negative values for DB_POOL_MAX environment variable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant