CI / quality (push) Waiting to run
- postgres.js forwarded schema as a startup param; Postgres rejected the connection - Remove ?schema=public from docker-compose, CI, and the client default - Strip any query string in lib/db/index.ts so this cannot recur
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { drizzle } from "drizzle-orm/postgres-js";
|
|
import postgres from "postgres";
|
|
|
|
import * as schema from "./schema";
|
|
|
|
/**
|
|
* The Drizzle database client (postgres.js driver), matching the house standard
|
|
* used by the other projects. Replaces the old Prisma client (`lib/prisma.ts`).
|
|
* A single connection is reused across hot reloads in dev.
|
|
*/
|
|
// Strip any query string (e.g. a leftover Prisma `?schema=public`) — postgres.js
|
|
// forwards unknown params to the server as startup options and Postgres rejects
|
|
// them ("unrecognized configuration parameter"). `public` is the default schema.
|
|
const connectionString = (
|
|
process.env.DATABASE_URL ?? "postgresql://postgres:postgres@localhost:5432/moh_sass"
|
|
).split("?")[0];
|
|
|
|
const globalForDb = globalThis as unknown as {
|
|
dbClient: ReturnType<typeof postgres> | undefined;
|
|
};
|
|
|
|
const client = globalForDb.dbClient ?? postgres(connectionString);
|
|
|
|
if (process.env.NODE_ENV !== "production") {
|
|
globalForDb.dbClient = client;
|
|
}
|
|
|
|
export const db = drizzle(client, { schema });
|
|
export { schema };
|