()
| 1 | import type { ClientConfig } from 'pg'; |
| 2 | |
| 3 | export 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'; |
no outgoing calls
no test coverage detected