diff --git a/src/libs/DB.ts b/src/libs/DB.ts index 1fbdd224f..ffc9780ec 100644 --- a/src/libs/DB.ts +++ b/src/libs/DB.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { PGlite } from '@electric-sql/pglite'; import { drizzle as drizzlePg } from 'drizzle-orm/node-postgres'; import { migrate as migratePg } from 'drizzle-orm/node-postgres/migrator'; -import { drizzle as drizzlePglite } from 'drizzle-orm/pglite'; +import { drizzle as drizzlePglite, type PgliteDatabase } from 'drizzle-orm/pglite'; import { migrate as migratePglite } from 'drizzle-orm/pglite/migrator'; import { PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants'; import { Client } from 'pg'; @@ -26,15 +26,17 @@ if (process.env.NEXT_PHASE !== PHASE_PRODUCTION_BUILD && Env.DATABASE_URL) { migrationsFolder: path.join(process.cwd(), 'migrations'), }); } else { - const global = globalThis as unknown as { client: PGlite }; + const global = globalThis as unknown as { client: PGlite; drizzle: PgliteDatabase }; if (!global.client) { global.client = new PGlite(); await global.client.waitReady; + + global.drizzle = drizzlePglite(global.client, { schema }); } - drizzle = drizzlePglite(global.client, { schema }); - await migratePglite(drizzle, { + drizzle = global.drizzle; + await migratePglite(global.drizzle, { migrationsFolder: path.join(process.cwd(), 'migrations'), }); }