fix: restore PrismaPg adapter for Prisma v7 compatibility

This commit is contained in:
AyrisAI
2026-07-23 17:52:18 +03:00
parent 2c557215e1
commit a2d6cf653d
4 changed files with 230 additions and 189 deletions
+10 -11
View File
@@ -1,23 +1,22 @@
import { Pool } from 'pg';
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from '@prisma/client';
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
};
function createPrismaClient() {
const databaseUrl = process.env.DATABASE_URL;
function createPrismaClient(): PrismaClient {
const connectionString =
process.env.DATABASE_URL ||
'postgres://postgres:mBTWE2cDKGExtpktguD3HPe8y9Xr9kWFYdxV4WHQKISLLGoBAS4UdtfSCfXwvPpq@65.109.236.58:37298/postgres';
if (!databaseUrl) {
console.error('[DB] DATABASE_URL is not set! Using fallback connection string.');
}
return new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
});
const pool = new Pool({ connectionString });
const adapter = new PrismaPg(pool);
return new PrismaClient({ adapter });
}
export const db =
globalForPrisma.prisma ?? createPrismaClient();
export const db = globalForPrisma.prisma ?? createPrismaClient();
if (process.env.NODE_ENV !== 'production') {
globalForPrisma.prisma = db;