- Add lib/db (schema, postgres.js client, enums, seed, migrations) on Drizzle - Rewrite all lib and admin action queries from Prisma to Drizzle - Keep existing table/column names so no data migration is needed - Preserve signed-cookie admin auth unchanged - Map unique-violation handling from Prisma P2002 to SQLSTATE 23505 - Swap deps, scripts, Makefile, and Dockerfile from Prisma to Drizzle
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
|
||||
import * as schema from "./schema";
|
||||
|
||||
const rawConnectionString =
|
||||
process.env.DATABASE_URL ?? "postgresql://postgres:postgres@localhost:5432/moh_sass";
|
||||
|
||||
// Prisma allowed a `?schema=public` query param that postgres.js does not
|
||||
// understand — strip any unknown query string; `public` is the default schema.
|
||||
const connectionString = rawConnectionString.split("?")[0];
|
||||
|
||||
const globalForDb = globalThis as unknown as {
|
||||
pgClient: ReturnType<typeof postgres> | undefined;
|
||||
};
|
||||
|
||||
const client = globalForDb.pgClient ?? postgres(connectionString, { max: 10 });
|
||||
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
globalForDb.pgClient = client;
|
||||
}
|
||||
|
||||
export const db = drizzle(client, { schema });
|
||||
export { schema };
|
||||
Reference in New Issue
Block a user