← back to Restaurant Directory
src/api/_pg-defaults.ts
15 lines
// Set PG env defaults BEFORE anything imports directory-core/db.
// directory-core/db lazily reads env on first pool access; whatever's set
// in process.env at that moment wins. The `??=` operator only assigns if
// the var is currently undefined, so explicit env values from shell/.env
// always take precedence over these defaults.
//
// Why a separate module: ESM hoists ALL imports above mutable code in the
// importing file. To set env BEFORE another import runs, the assignments
// must live in a module that's imported FIRST.
//
// Source: defaults preserved from the inline `new Pool({...})` in
// src/api/server.ts that this migration replaces (2026-05-04).
process.env.PGHOST ??= '/tmp';
process.env.PGDATABASE ??= 'restaurant_professional_directory';