MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / computeDatabaseUrl

Function computeDatabaseUrl

packages/db/src/database-url.ts:3–20  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1import type { ClientConfig } from 'pg';
2
3export function computeDatabaseUrl(): string {
4 const useProductionDb = process.env.USE_PRODUCTION_DB === 'true';
5
6 const postgresUrl = useProductionDb
7 ? process.env.POSTGRES_URL_PRODUCTION || ''
8 : process.env.POSTGRES_URL || '';
9
10 if (!postgresUrl) {
11 throw new Error(
12 useProductionDb ? 'POSTGRES_URL_PRODUCTION not configured' : 'POSTGRES_URL not configured'
13 );
14 }
15
16 if (process.env.NODE_ENV !== 'test') {
17 return postgresUrl;
18 }
19
20 // Isolate each Jest worker's database. Append to the path segment so query
21 // parameters such as sslmode stay valid instead of becoming part of the
22 // last parameter's value.
23 const workerId = process.env.JEST_WORKER_ID || '1';

Callers 8

drizzle.config.tsFile · 0.90
schema.test.tsFile · 0.90
drizzle.tsFile · 0.90
getSeedDbFunction · 0.90
ensureTestUserFunction · 0.90
mainFunction · 0.90
createDbFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected