import { drizzle } from "drizzle-orm/postgres-js"; import postgres from "postgres"; import * as schema from "./schema"; // No pooler in front of this for the MVP: DATABASE_URL points straight at // Postgres, and postgres-js already pools connections in-process (`max`). // // `prepare: false` is kept deliberately so a transaction-mode pooler can be // added later without touching this file. Which one matters - measured // 2026-10-20: through pgCat 1.2.0 any query with a bind parameter hangs // forever (every Drizzle query has one), while PgBouncer 1.22 in transaction // mode runs the same queries and passes scripts/e2e-authz.sh. See PLAN.md. // // Migrations go straight at Postgres either way: drizzle.config.ts cannot // pass `prepare: false`, and drizzle-kit hung at commit through pgCat. const connectionString = process.env.DATABASE_URL; if (!connectionString) { throw new Error("DATABASE_URL is not set"); } const client = postgres(connectionString, { prepare: false, max: Number(process.env.DATABASE_POOL_MAX ?? 10), }); export const db = drizzle(client, { schema }); export type Database = typeof db;