[NO-ISSUE] 같은 기기 토큰 재할당·계정 전환 시 FCM 토큰 unique 충돌 방지#267
Merged
Conversation
같은 물리 기기에서 FCM 토큰이 다른 row 로 재할당되거나 계정을 전환할 때, token 기준으로 찾은 row 의 (user_id, device_id) 를 갱신하는 순간 기존 device row 와 unique(user_id, device_id) 제약이 충돌해 등록 API 가 500 으로 실패하던 문제 수정. - syncExistingToken 에서 대상 row 갱신 전, 동일 (userId, deviceId) 의 다른 row 를 벌크 삭제(@Modifying)하여 Hibernate update-before-delete flush 순서로 인한 충돌 회피 - FcmTokenRepository.deleteByUserIdAndDeviceIdExcludingId 추가 - 실제 unique 제약이 적용되는 @DataJpaTest 통합 테스트로 재현·검증 (전체 410개 통과) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
WalkthroughFCM 토큰 등록 시 동일한 (userId, deviceId) 조합에서 기존 row를 제외한 다른 레코드를 먼저 삭제하는 로직을 추가하여 unique 제약 위반을 방지합니다. 저장소에 bulk delete 메서드를 정의하고, 서비스에서 이를 호출하며, 두 가지 시나리오를 검증하는 persistence 테스트를 포함합니다. ChangesFCM Token Unique Constraint Handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
PR #266 리뷰에서 보류했던 계정 전환 시
(user_id, device_id)unique 충돌(P2) 을 수정합니다.문제
같은 물리 기기에서 FCM 토큰이 다른 row로 재할당되거나 계정을 전환할 때,
findByToken으로 찾은 row의(user_id, device_id)를 갱신하는 순간 기존 device row와 unique 제약이 충돌해 토큰 등록 API가 500으로 실패.수정
syncExistingToken에서 대상 row 갱신 전에 동일(userId, deviceId)의 다른 row를 벌크 삭제(@Modifying)하여, Hibernate의 update-before-delete flush 순서로 인한 충돌을 회피FcmTokenRepository.deleteByUserIdAndDeviceIdExcludingId추가검증
@DataJpaTest통합 테스트로 충돌을 재현하고 수정으로 해소됨을 확인 (수정 제거 시 테스트 실패하는 것까지 검증)🤖 Generated with Claude Code
Summary by CodeRabbit
릴리스 노트