Skip to content

fix: 시드 재실행이 리뷰 댓글 FK로 실패하던 문제 수정 - #534

Merged
chanwoo7 merged 2 commits into
developfrom
fix/seed-review-comment-cleanup
Oct 15, 2026
Merged

chanwoo7 merged 2 commits into
developfrom
fix/seed-review-comment-cleanup

Conversation

@chanwoo7

@chanwoo7 chanwoo7 commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

배경

  • 로컬에서 시드 리뷰에 댓글이 1건이라도 달려 있으면 yarn prisma:seed 재실행이 실패합니다.
    • 실패 지점: resetSeedScope의 prisma.review.deleteMany()(Foreign key constraint violated on review_id)
    • 시드 사용자가 시드 밖 리뷰에 댓글을 단 경우에는 시드 계정 삭제가 account_id FK에 막힙니다.
  • 원인은 review_comment의 review_id·account_id FK가 둘 다 RESTRICT인데, resetSeedScope의 정리 대상에 review_comment가 빠져 있던 것입니다.
    • review_report.review_comment_id는 SET NULL이라 함께 정리할 필요가 없습니다.
  • FE 로컬 개발 가이드를 검증하던 중 로컬 DB에서 실제로 재현했습니다(9/29에 남긴 댓글 1건).

변경

  • prisma/seed/idempotent.ts에 댓글 정리를 두 곳 추가했습니다.
    • 주문 아이템 기준 리뷰 삭제 앞: 그 리뷰들에 달린 댓글(작성자 무관)
    • 사용자 기준 리뷰 삭제 앞: 시드 사용자가 쓴 댓글과 시드 사용자 리뷰에 달린 댓글
  • 시드 밖 리뷰 자체는 지우지 않습니다. 시드 사용자가 그 리뷰에 단 댓글만 지웁니다.
  • 신고 정리 단계에 시드 리뷰(시드 사용자 작성·시드 매장)의 댓글을 대상으로 한 신고도 추가했습니다(리뷰 지적 반영).
    • 댓글만 지우면 신고가 SET NULL로 대상 없는 PENDING이 되고, 대시보드 대기 신고 수에 계속 잡힙니다.

테스트

  • src/test/seed-reset-scope.spec.ts에 실 DB 회귀 테스트 4건을 추가했습니다. 실제 시드 함수로 리뷰까지 채운 뒤 정리합니다.
    • 시드 리뷰에 외부 계정이 단 댓글이 있어도 정리하고 다시 시드한다
    • 시드 리뷰에 달린 외부 댓글의 외부 신고도 지워 대상 없는 신고가 남지 않는다
    • 시드 사용자가 시드 밖 리뷰에 단 댓글은 지우고 그 리뷰는 남긴다
    • 시드 주문 밖에 있는 시드 사용자 리뷰의 댓글도 지운다
  • 반증을 확인했습니다.
    • 댓글 정리를 역적용하면 기존 3건이 모두 FK 위반(review_id·account_id·review_id)으로 실패합니다.
    • 신고 정리 조건을 역적용하면 신고 테스트 1건이 실패합니다.
    • 모두 적용하면 4건이 통과합니다.
  • 시드(prisma/)와 src/test/는 커버리지 수집 대상이 아니라 임계에는 영향이 없습니다.

플랜 대조

승인 범위("정리 대상 추가 + 재현 테스트") 상태
resetSeedScope에 review_comment 정리 추가(리뷰 FK·계정 FK 양쪽) 한 것
재현 테스트(시드 → 댓글 → 재시드 성공) + 반증 한 것

- 증상: 로컬에서 시드 리뷰에 댓글이 1건이라도 있으면 yarn prisma:seed 재실행이 resetSeedScope의 review.deleteMany에서 FK 위반으로 실패. 시드 사용자가 시드 밖 리뷰에 댓글을 달아도 계정 삭제가 막힘
- 원인: review_comment의 review_id·account_id FK가 둘 다 RESTRICT인데 resetSeedScope 정리 대상에 review_comment가 없음(review_report의 댓글 FK는 SET NULL이라 해당 없음)
- 변경: 주문 아이템 기준 리뷰 삭제 앞에 그 리뷰의 댓글 삭제, 사용자 기준 리뷰 삭제 앞에 시드 사용자가 쓴 댓글과 시드 사용자 리뷰의 댓글 삭제
- 회귀 테스트 3건(src/test/seed-reset-scope.spec.ts, 실 시드 함수로 리뷰까지 채운 뒤 정리): 시드 리뷰에 외부 계정 댓글 → 정리 후 재시드 / 시드 사용자가 외부 리뷰에 단 댓글 → 댓글만 삭제·리뷰 유지 / 시드 주문 밖 시드 사용자 리뷰의 댓글 삭제
- 반증: 수정 역적용 시 3건 모두 FK 위반(review_id·account_id·review_id)으로 실패, 재적용 시 3건 통과
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: CaQuick/caquick-be/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 02787796-21be-40cc-8a24-609f8930d5e5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T12:20:44.720203Z f83757c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

🧹 knip — dead-code 리포트

Unused exported types (1)
전체 리포트
Unused exported types (1)
RateLimitPolicy  type  src/global/rate-limit/index.ts:4:8

청소 후보(오탐 가능) · 기준 docs/guide/architecture-conventions.md

@github-actions

Copy link
Copy Markdown

🩺 NestJS Doctor — 90/100 (Excellent)

진단 486건 (error 12).

Category error warning info
architecture 1 1 44
correctness 0 268 0
performance 0 36 28
schema 0 0 76
security 11 21 0
architecture / security 상위 항목
  • error architecture/architecture/no-manual-instantiation: Manual instantiation of 'OutboxRepository' detected. Use dependency injection instead.
  • info architecture/architecture/no-barrel-export-internals: Barrel file re-exports internal type 'IAuditLogRepository'.
  • warning security/security/no-exposed-env-vars: Direct 'process.env.NODE_ENV' access in 'AuthController'. Use ConfigService instead.
  • warning security/security/require-guards-on-endpoints: Endpoint 'start' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'callback' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'refresh' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'logout' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'sellerLogin' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'sellerRefresh' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'sellerLogout' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'devIssueToken' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'adminLogin' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'adminRefresh' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'adminLogout' has no @UseGuards() at class or method level.
  • warning security/security/require-guards-on-endpoints: Endpoint 'getJwks' has no @UseGuards() at class or method level.

오탐 포함 가능 · 기준 docs/guide/architecture-conventions.md

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6ad44459ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread prisma/seed/idempotent.ts
Comment on lines +102 to +104
await prisma.reviewComment.deleteMany({
where: { review: { order_item_id: { in: orderItemIds } } },
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Settle comment reports before deleting seeded-review comments

When an external user reports an external user's comment on a seeded review, the earlier reviewReport.deleteMany does not match it because comment reports have no review_id and the comment author is not seeded. This hard delete therefore only applies the FK's ON DELETE SET NULL, leaving a PENDING report with both target IDs null and its open_key intact; ReviewAdminRepository.targetedReportWhere then excludes it from listing, detail, and resolution forever. Delete or resolve reports selected through review_comment.review before deleting these comments; the second newly added comment-deletion path has the same issue.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영: 0) 신고 정리 단계에 "시드 리뷰(시드 사용자 작성·시드 매장)에 달린 댓글을 대상으로 한 신고" 조건 추가 — 댓글 삭제 전에 지워 대상 없는 PENDING이 남지 않음. 대시보드 대기 신고 수(countPendingReviewReports)가 대상 없는 PENDING까지 세므로 실제 불일치. 시드 사용자가 남의 리뷰에 단 댓글의 신고는 기존 review_comment.account_id 조건이 이미 덮음. 회귀 테스트 1건 추가.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Coverage report

St.❔
Category Percentage Covered / Total
🟢 Statements 98.02% 10791/11009
🟢 Branches 92.95% 4112/4424
🟢 Functions 97.55% 2150/2204
🟢 Lines 98.59% 9818/9958

Test suite run success

4296 tests passing in 387 suites.

Report generated by 🧪jest coverage report action from f83757c

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- 리뷰 #534 지적 반영: 시드 리뷰의 댓글을 지우면 그 댓글 신고가 SET NULL로 대상 없는 PENDING이 됨. 신고 목록은 targetedReportWhere로 숨기지만 대시보드 대기 신고 수(countPendingReviewReports)는 계속 셈
- 0) 신고 정리에 시드 리뷰(시드 사용자 작성·시드 매장) 댓글 대상 신고 조건 추가
- 회귀 테스트 1건(외부 댓글의 외부 신고). 반증: 수정 역적용 시 이 1건 실패, 적용 시 4건 통과
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant