fix: remove pg adapter, use standard PrismaClient - add prisma db push to Dockerfile CMD
This commit is contained in:
@@ -1,34 +1,24 @@
|
||||
import { Pool } from 'pg';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const connectionString =
|
||||
process.env.DATABASE_URL ||
|
||||
'postgres://postgres:mBTWE2cDKGExtpktguD3HPe8y9Xr9kWFYdxV4WHQKISLLGoBAS4UdtfSCfXwvPpq@65.109.236.58:37298/postgres';
|
||||
|
||||
const pool = new Pool({ connectionString });
|
||||
const adapter = new PrismaPg(pool);
|
||||
|
||||
const globalForPrisma = globalThis as unknown as {
|
||||
prisma: PrismaClient | undefined;
|
||||
};
|
||||
|
||||
function getPrismaClient(): PrismaClient {
|
||||
if (process.env.NODE_ENV !== 'production' && globalForPrisma.prisma) {
|
||||
// Ensure all models (category, cheatsheet, prompt) exist on cached client
|
||||
if (
|
||||
(globalForPrisma.prisma as any).category &&
|
||||
(globalForPrisma.prisma as any).cheatsheet &&
|
||||
(globalForPrisma.prisma as any).prompt
|
||||
) {
|
||||
return globalForPrisma.prisma;
|
||||
}
|
||||
function createPrismaClient() {
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
|
||||
if (!databaseUrl) {
|
||||
console.error('[DB] DATABASE_URL is not set! Using fallback connection string.');
|
||||
}
|
||||
const client = new PrismaClient({ adapter });
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
globalForPrisma.prisma = client;
|
||||
}
|
||||
return client;
|
||||
|
||||
return new PrismaClient({
|
||||
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
|
||||
});
|
||||
}
|
||||
|
||||
export const db = getPrismaClient();
|
||||
export const db =
|
||||
globalForPrisma.prisma ?? createPrismaClient();
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
globalForPrisma.prisma = db;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user