fix: 프로덕션 DB 스키마 미적용 및 PrismaClient 싱글톤 수정
- deploy.sh에 prisma db push 단계 추가 (배포 시 스키마 자동 적용) - Dockerfile에 Prisma schema 런타임 이미지 복사 추가 - PrismaClient 프로덕션 싱글톤 캐시 활성화 (커넥션 풀 소진 방지)
This commit is contained in:
@@ -34,6 +34,10 @@ COPY . .
|
|||||||
RUN cd packages/database && npx prisma generate
|
RUN cd packages/database && npx prisma generate
|
||||||
RUN pnpm turbo run build --filter=@startover/${APP_NAME}
|
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
|
# Ensure public directories exist for COPY
|
||||||
RUN mkdir -p /app/apps/${APP_NAME}/public
|
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 /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/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/${APP_NAME}/.next/static ./apps/${APP_NAME}/.next/static
|
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
|
USER nextjs
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|||||||
+12
-3
@@ -55,9 +55,18 @@ fi
|
|||||||
log "Building and deploying with Docker Compose..."
|
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"
|
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
|
# Wait for postgres to be healthy
|
||||||
log "Waiting for services to be healthy..."
|
log "Waiting for postgres to be healthy..."
|
||||||
sleep 15
|
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
|
# Health check
|
||||||
if curl -sf http://localhost/health > /dev/null 2>&1; then
|
if curl -sf http://localhost/health > /dev/null 2>&1; then
|
||||||
|
|||||||
@@ -12,15 +12,10 @@ export function createPrismaClient(): PrismaClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const client = new PrismaClient({
|
const client = new PrismaClient({
|
||||||
log:
|
log: process.env['NODE_ENV'] === 'development' ? ['query', 'error', 'warn'] : ['error'],
|
||||||
process.env['NODE_ENV'] === 'development'
|
|
||||||
? ['query', 'error', 'warn']
|
|
||||||
: ['error'],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (process.env['NODE_ENV'] !== 'production') {
|
prismaInstance = client;
|
||||||
prismaInstance = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user