fix: 프로덕션 DB 스키마 미적용 및 PrismaClient 싱글톤 수정

- deploy.sh에 prisma db push 단계 추가 (배포 시 스키마 자동 적용)
- Dockerfile에 Prisma schema 런타임 이미지 복사 추가
- PrismaClient 프로덕션 싱글톤 캐시 활성화 (커넥션 풀 소진 방지)
This commit is contained in:
Johngreen
2026-03-08 23:26:29 +09:00
parent de531bfe11
commit 0c705d00e2
3 changed files with 19 additions and 10 deletions
+5
View File
@@ -34,6 +34,10 @@ COPY . .
RUN cd packages/database && npx prisma generate
RUN pnpm turbo run build --filter=@startover/${APP_NAME}
# Copy Prisma schema and engine for runtime migration
RUN mkdir -p /app/prisma
RUN cp packages/database/prisma/schema.prisma /app/prisma/schema.prisma
# Ensure public directories exist for COPY
RUN mkdir -p /app/apps/${APP_NAME}/public
@@ -50,6 +54,7 @@ WORKDIR /app
COPY --from=builder /app/apps/${APP_NAME}/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/apps/${APP_NAME}/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/${APP_NAME}/.next/static ./apps/${APP_NAME}/.next/static
COPY --from=builder /app/prisma/schema.prisma ./prisma/schema.prisma
USER nextjs
EXPOSE 3000
+12 -3
View File
@@ -55,9 +55,18 @@ fi
log "Building and deploying with Docker Compose..."
docker compose -f docker-compose.prod.yml --env-file .env.production up -d --build --remove-orphans 2>&1 | tee -a "$LOG_FILE"
# Wait for services
log "Waiting for services to be healthy..."
sleep 15
# Wait for postgres to be healthy
log "Waiting for postgres to be healthy..."
sleep 10
# Apply database schema
log "Applying database schema (prisma db push)..."
docker compose -f docker-compose.prod.yml --env-file .env.production exec -T web npx prisma db push --schema=./prisma/schema.prisma --skip-generate --accept-data-loss 2>&1 | tee -a "$LOG_FILE"
log "Database schema applied."
# Wait for services to stabilize
log "Waiting for services to stabilize..."
sleep 5
# Health check
if curl -sf http://localhost/health > /dev/null 2>&1; then
+2 -7
View File
@@ -12,15 +12,10 @@ export function createPrismaClient(): PrismaClient {
}
const client = new PrismaClient({
log:
process.env['NODE_ENV'] === 'development'
? ['query', 'error', 'warn']
: ['error'],
log: process.env['NODE_ENV'] === 'development' ? ['query', 'error', 'warn'] : ['error'],
});
if (process.env['NODE_ENV'] !== 'production') {
prismaInstance = client;
}
prismaInstance = client;
return client;
}