update 2
This commit is contained in:
+19
-14
@@ -5,29 +5,34 @@ declare global {
|
||||
var prisma: PrismaClient | undefined;
|
||||
}
|
||||
|
||||
let prisma: PrismaClient;
|
||||
// Guard: don't attempt a real DB connection at build time when env vars are absent.
|
||||
// During `next build` inside Docker, DB_HOST is not injected — only available at runtime.
|
||||
function createPrismaClient(connectionLimit: number): PrismaClient {
|
||||
if (!process.env.DB_HOST) {
|
||||
// Return a shell client with no adapter — all queries will throw and be caught
|
||||
// by the try/catch in callers (e.g. getSettings returns DEFAULT_SETTINGS).
|
||||
return new PrismaClient();
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
const adapter = new PrismaMariaDb({
|
||||
host: process.env.DB_HOST,
|
||||
port: Number(process.env.DB_PORT),
|
||||
port: Number(process.env.DB_PORT) || 3306,
|
||||
user: process.env.DB_USERNAME,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
connectionLimit: 10,
|
||||
connectionLimit,
|
||||
});
|
||||
prisma = new PrismaClient({ adapter });
|
||||
|
||||
return new PrismaClient({ adapter });
|
||||
}
|
||||
|
||||
let prisma: PrismaClient;
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
prisma = createPrismaClient(10);
|
||||
} else {
|
||||
if (!global.prisma) {
|
||||
const adapter = new PrismaMariaDb({
|
||||
host: process.env.DB_HOST,
|
||||
port: Number(process.env.DB_PORT),
|
||||
user: process.env.DB_USERNAME,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
connectionLimit: 5,
|
||||
});
|
||||
global.prisma = new PrismaClient({ adapter });
|
||||
global.prisma = createPrismaClient(5);
|
||||
}
|
||||
prisma = global.prisma;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user