Skip to content

feat: enhance configuration with database connection settings and pool tuning#104

Merged
greatest0fallt1me merged 2 commits intoCalloraOrg:mainfrom
Baskarayelu:set-up
Feb 26, 2026
Merged

feat: enhance configuration with database connection settings and pool tuning#104
greatest0fallt1me merged 2 commits intoCalloraOrg:mainfrom
Baskarayelu:set-up

Conversation

@Baskarayelu
Copy link
Contributor

@Baskarayelu Baskarayelu commented Feb 26, 2026

Summary

  • Add PostgreSQL connection pooling and a shared client helper.
  • Enhance /api/health to reflect database connectivity (ok vs degraded).
  • Document DATABASE_URL and pool tuning environment variables.

Details

  • Config & pooling

    • Extend config to include:
      • databaseUrl (from DATABASE_URL, with a local default).
      • dbPool options derived from env vars:
        • DB_POOL_MAX
        • DB_IDLE_TIMEOUT_MS
        • DB_CONN_TIMEOUT_MS
    • Update db.ts to:
      • Instantiate a shared pg.Pool using the centralized config.
      • Export a query(text, params?) helper for simple one-off queries.
      • Add checkDbHealth() which executes SELECT 1 and returns { ok, error? }, logging failures if the DB is unavailable.
  • Health endpoint

    • Update HealthResponse in types/index.ts to:
      • Use status: 'ok' | 'degraded'.
      • Include a db object: { status: 'ok' | 'error', error?: string }.
    • Update /api/health (router) to:
      • Call checkDbHealth() on each request.
      • Return status: "ok" when the DB is reachable.
      • Return status: "degraded" and db.status: "error" (with error message) when the DB is down or misconfigured.
  • Environment documentation

    • Add .env.example documenting:
      • PORT, NODE_ENV.
      • DATABASE_URL with an example that matches docker-compose and a local default.
      • Optional pool tuning knobs: DB_POOL_MAX, DB_IDLE_TIMEOUT_MS, DB_CONN_TIMEOUT_MS.

Configuration

  • Required

    • DATABASE_URL must point to a reachable PostgreSQL instance.
  • Optional

    • DB_POOL_MAX – max clients in pool (default: 10).
    • DB_IDLE_TIMEOUT_MS – idle client lifetime in ms (default: 30000).
    • DB_CONN_TIMEOUT_MS – acquire timeout in ms (default: 2000).

Test Plan

@greatest0fallt1me
Copy link
Contributor

LGTM!

@greatest0fallt1me greatest0fallt1me merged commit 3b22185 into CalloraOrg:main Feb 26, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants