Skip to content

fix: 시드 밖 계정의 시드 상품 주문이 재시드를 막던 문제 수정 - #536

Merged
chanwoo7 merged 2 commits into
developfrom
fix/seed-outside-orders
Oct 15, 2026
Merged

chanwoo7 merged 2 commits into
developfrom
fix/seed-outside-orders

Conversation

@chanwoo7

@chanwoo7 chanwoo7 commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

배경

  • fix: 시드 밖 계정의 시드 상품 주문·리뷰가 재시드를 막음 #535: 시드 밖 계정(로컬 구매자 테스트 계정 등)이 시드 매장 상품을 주문하거나 리뷰를 남기면 yarn prisma:seed 재실행이 시드 상품 삭제에서 실패합니다.
    • order_item.product_id·order_item.store_id·review.product_id·review.store_id FK가 모두 RESTRICT입니다.
    • resetSeedScope가 주문을 시드 사용자 기준으로만 지워, 시드 밖 계정의 주문 품목과 리뷰가 남았습니다.
  • 찜·최근 본 상품·매장 대화는 이미 상품·매장 기준으로 정리하고 있어 해당하지 않습니다.

변경

  • 주문 정리 대상을 "시드 사용자의 주문"과 "시드 매장 품목이 든 주문"으로 넓혔습니다.
    • 주문은 상품 하나로 만들어지므로(createOrder의 productId) 매장도 하나입니다. 그래서 시드 밖 매장의 품목이 함께 지워지지 않습니다.
    • 그 아래 품목·옵션·커스텀·리뷰(좋아요·미디어·댓글) 정리는 기존 블록을 그대로 탑니다. 리뷰·댓글 신고는 #534의 0) 단계가 시드 매장 기준으로 이미 지웁니다.
  • 주문 정리를 시드 사용자 조건(userIds.length > 0) 밖의 별도 블록으로 옮겼습니다(리뷰 지적 반영).
    • 시드 사용자 계정은 1) 단계 끝에서 지워지는데, 실패는 2) 상품 삭제에서 납니다.
    • 그래서 이미 한 번 실패한 DB에는 시드 사용자 없이 시드 매장과 막는 주문만 남고, 조건 안에 두면 그 상태가 복구되지 않습니다.
  • 이 주문·품목·리뷰를 가리키는 알림도 함께 지웁니다.

테스트

  • src/test/seed-reset-scope.spec.ts에 실 DB 회귀 테스트 3건을 추가했습니다(총 7건).
    • 시드 밖 계정이 시드 상품을 주문하고 리뷰를 남겨도 정리하고 다시 시드한다
    • 시드 밖 계정이 시드 밖 매장에 넣은 주문은 남긴다
    • 시드 사용자 없이 시드 매장과 시드 밖 주문만 남은 상태(이전 재시드 실패)도 정리한다
  • 반증을 확인했습니다.
    • 수정을 모두 역적용하면 첫 번째 테스트가 Foreign key constraint violated on the fields: (product_id)로 실패합니다.
    • 알림 정리만 빼면 첫 번째 테스트가 알림이 남아 실패합니다.
    • 조회 조건을 모든 주문으로 넓히면 두 번째 테스트(와 기존 보존 테스트 1건)가 실패합니다.
    • 주문 정리를 시드 사용자 조건 안으로 되돌리면 세 번째 테스트가 product_id FK 위반으로 실패합니다.
    • 수정을 적용하면 7건이 모두 통과합니다.

플랜 대조

#535 "정리 방향(제안)" 상태
시드 매장 주문 품목을 가진 주문을 계정과 무관하게 함께 정리 한 것
해당 주문 품목·리뷰(및 하위 댓글·신고·미디어) 정리 한 것 — 기존 주문 정리 블록과 #534의 신고 정리로 처리
seed-reset-scope.spec.ts에 "시드 밖 계정이 시드 상품을 주문·리뷰한 뒤 재시드" 케이스 추가 한 것

- #535: 시드 밖 계정(로컬 구매자 테스트 계정 등)이 시드 매장 상품을 주문·리뷰하면 order_item·review의 product_id·store_id FK(RESTRICT) 때문에 재시드가 시드 상품 삭제에서 실패
- resetSeedScope 주문 정리 대상을 '시드 사용자 주문 + 시드 매장 품목이 든 주문'으로 넓힘. 주문은 상품 하나로 만들어져 매장도 하나라 시드 밖 매장 품목은 함께 지워지지 않음
- 이 주문·품목·리뷰를 가리키는 알림도 함께 삭제 — SET NULL로 대상 없는 알림이 남지 않게(#534 신고 건과 같은 축)
- 회귀 테스트 2건(시드 상품 주문·리뷰 뒤 재시드, 시드 밖 매장 주문 보존). 반증: 수정 역적용 시 FK(product_id) 실패, 알림 정리만 빼면 알림 잔존으로 실패, 조회 조건을 전체로 넓히면 보존 테스트 실패
@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: b6bb0d2e-91e8-42f9-be49-8f5bf0360386

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:47:04.887579Z cf0be14 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: 80ae5a21c0

ℹ️ 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
where: {
OR: [
{ account_id: { in: userIds } },
{ items: { some: { store_id: { in: storeIds } } } },

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 Run seed-store order cleanup without requiring seed users

When retrying after the original failure, this predicate is never reached because the entire order-cleanup block remains guarded by userIds.length > 0. The previous non-transactional reset deletes the seed users before reaching product deletion, where an outsider's order item causes the FK failure; consequently, the database state this fix must recover has seed stores and the blocking order but no seed users. A subsequent seed attempt still skips this query and fails at product deletion again, requiring manual cleanup instead of restoring idempotency. Move the seed-store order cleanup outside the user-only guard (while retaining user-specific cleanup separately).

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.

반영: 주문 정리 블록을 userIds.length > 0 밖의 별도 블록(userIds.length > 0 || storeIds.length > 0)으로 이동. 시드 사용자 계정은 1) 끝에서 지워지고 실패는 2) 상품 삭제에서 나므로, 이미 한 번 실패한 DB(시드 사용자 없음 + 시드 매장·막는 주문 잔존)가 이번 수정으로도 복구되지 않던 경로가 맞음. 시드 매장만 있는 상태 재현 테스트 추가.

@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

4299 tests passing in 387 suites.

Report generated by 🧪jest coverage report action from cf0be14

@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!

- 리뷰 #536 지적 반영: 주문 정리가 userIds.length > 0 블록 안에 있어, 이전 재시드가 2) 상품 삭제에서 실패한 DB(시드 사용자는 1) 끝에서 이미 삭제, 시드 매장·막는 주문 잔존)는 다시 돌려도 복구되지 않음
- 주문 정리를 사용자 조건과 분리(userIds 또는 storeIds가 있으면 실행), 나머지 유저 종속은 기존 조건 유지
- 회귀 테스트 1건(시드 매장만 남은 상태 재현). 반증: 사용자 조건을 되살리면 FK(product_id)로 실패, 적용 시 7건 통과
@chanwoo7
chanwoo7 merged commit 430c181 into develop Oct 15, 2026
16 checks passed
@chanwoo7
chanwoo7 deleted the fix/seed-outside-orders branch October 15, 2026 12:49
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