Исправление: Prisma singleton pattern + повторная генерация перед сборкой

This commit is contained in:
DeepAgent
2025-10-28 09:14:51 +00:00
parent 90081ba46d
commit af9216f38d
4 changed files with 35 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@@ -41,6 +41,17 @@ RUN yarn install --network-timeout 300000 --network-concurrency 4 && \
RUN npx prisma generate --schema=./prisma/schema.prisma && \
echo "✅ Prisma Client сгенерирован"
# Проверяем что клиент действительно создался
RUN echo "=== Проверка Prisma Client ===" && \
test -d node_modules/.prisma/client && \
test -f node_modules/.prisma/client/index.js && \
ls -la node_modules/.prisma/client/ | head -10 && \
echo "✅ Prisma Client файлы на месте"
# ВАЖНО: Повторная генерация перед сборкой (для уверенности)
RUN npx prisma generate --schema=./prisma/schema.prisma && \
echo "✅ Prisma Client пересоздан перед сборкой"
# Переменные окружения для сборки
ARG NEXT_PUBLIC_SITE_URL
ENV NEXT_PUBLIC_SITE_URL=${NEXT_PUBLIC_SITE_URL:-http://localhost:3000}

View File

@@ -1,13 +1,11 @@
import { NextRequest, NextResponse } from 'next/server'
import { PrismaClient } from '@prisma/client'
import { prisma } from '@/lib/prisma'
import { sendEmailNotification } from '@/lib/email'
import { sendTelegramNotification } from '@/lib/telegram'
export const dynamic = "force-dynamic"
const prisma = new PrismaClient()
export async function POST(request: NextRequest) {
try {
const body = await request.json()

View File

@@ -0,0 +1,22 @@
import { PrismaClient } from '@prisma/client'
// Singleton pattern для Prisma Client
// Использует lazy initialization - клиент создается только при первом использовании
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined
}
export const prisma =
globalForPrisma.prisma ??
new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
})
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
// Graceful shutdown
if (typeof window === 'undefined') {
process.on('beforeExit', async () => {
await prisma.$disconnect()
})
}