- Expand batch upload list area and optimize preview image layout - Improve upload speed tracking and display (server-side & client-side) - Reduce network detection log noise - Optimize Docker build process (caching, env validation) - Add shadow environment deployment support
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { PrismaClient } from '@prisma/client'
|
||
|
||
const globalForPrisma = global as unknown as { prisma: PrismaClient }
|
||
|
||
/**
|
||
* R9/R35修复:配置 Prisma 连接池
|
||
*
|
||
* 连接池参数说明:
|
||
* - connection_limit: 最大连接数(通过 DATABASE_URL 参数配置)
|
||
* - pool_timeout: 获取连接的超时时间
|
||
*
|
||
* 注意:核心连接池参数需要在 DATABASE_URL 中配置:
|
||
* DATABASE_URL="postgresql://...?connection_limit=10&pool_timeout=30"
|
||
*/
|
||
const prismaClientOptions = {
|
||
// 生产环境只记录错误和警告,开发环境记录所有查询
|
||
log: process.env.NODE_ENV === 'production'
|
||
? (['error', 'warn'] as ('error' | 'warn')[])
|
||
: (['query', 'error', 'warn'] as ('query' | 'error' | 'warn')[]),
|
||
}
|
||
|
||
export const prisma =
|
||
globalForPrisma.prisma ||
|
||
new PrismaClient(prismaClientOptions)
|
||
|
||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
|
||
|
||
// R47修复:在运行时验证环境变量(不在构建时验证)
|
||
if (typeof window === 'undefined') {
|
||
// 只在服务器端运行时验证
|
||
const { validateEnvironment } = require('./env-validation')
|
||
|
||
// 跳过验证的条件:
|
||
// 1. Next.js 构建时(NEXT_BUILD 环境变量存在)
|
||
// 2. 非生产环境(开发/测试)
|
||
const isBuildTime = process.env.NEXT_BUILD === '1'
|
||
const isNotProduction = process.env.NODE_ENV !== 'production'
|
||
|
||
if (!isBuildTime) {
|
||
try {
|
||
validateEnvironment()
|
||
} catch (error) {
|
||
console.error('[Prisma] ❌ 环境变量验证失败')
|
||
// 只在真正的生产运行时抛出错误
|
||
if (!isNotProduction) {
|
||
throw error
|
||
}
|
||
console.warn('[Prisma] ⚠️ 非 production 环境,跳过环境变量验证错误')
|
||
}
|
||
} else {
|
||
console.log('[Prisma] ℹ️ 构建时跳过环境变量验证')
|
||
}
|
||
}
|