The platform talks to Google Cloud SQL Postgres via the Cloud SQL Connector. Connection setup lives inDocumentation Index
Fetch the complete documentation index at: https://docs.appliedaifoundation.org/llms.txt
Use this file to discover all available pages before exploring further.
src/lib/db/postgres.ts.
Connection
GOOGLE_SERVICE_ACCOUNT_BASE64 env var. At startup:
- Decode the service account JSON
- Write it to a tmp file (mode
0o600), pointGOOGLE_APPLICATION_CREDENTIALSat it - Create a
Connectorinstance and request connection options for the configured Cloud SQL instance - Delete the tmp file
- Open a
pg.Poolwith the connector’s TCP options plusPOSTGRES_USER/POSTGRES_PASSWORD/POSTGRES_DB
Pool configuration
Retry logic
isTransientError() matches:
Type parsing
NUMERIC/DECIMAL (Postgres OID 1700) is parsed asfloat; INT8/BIGINT (OID 20) is parsed as int. Default pg behaviour is to return them as strings, which would break arithmetic everywhere — overridden in postgres.ts.
Graceful shutdown
SIGTERM and SIGINT handlers drain the pool and close the connector. Important on Vercel where deployments roll without warning.
Tables
Three configurable table names (src/lib/db/tables.ts):
Query helpers
postgres.ts exports query() and queryOne() helpers used everywhere instead of acquiring a client manually. They handle the retry-on-transient logic and ensure clients are released back to the pool.