-
Notifications
You must be signed in to change notification settings - Fork 3
[Refactpr][jjaeroong]: 회원탈퇴 시, provider_id를 null로 변경 #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
[Refactpr][jjaeroong]: 회원탈퇴 시, provider_id를 null로 변경
WalkthroughUser 엔티티의 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Svc as UserService
participant User as User(Entity)
participant DB as Database
Note over Svc,User: 사용자 삭제 처리 흐름 (수정됨)
Svc->>User: deleteUser()
rect rgba(200,230,255,0.3)
note right of User: 엔티티 필드 초기화
User->>User: nickname 재설정(삭제 표시)
User->>User: roles = [UNKNOWN]
User->>User: interests = [UNKNOWN]
User->>User: series 목록 비우기
User->>User: 개인 정보 null 처리
User->>User: providerId = null (신규)
end
User-->>Svc: 엔티티 상태 변경
Svc->>DB: 엔티티 저장(UPDATE)
DB-->>Svc: 성공/실패 결과
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/stackpot/stackpot/user/entity/User.java(2 hunks)
🔇 Additional comments (1)
src/main/java/stackpot/stackpot/user/entity/User.java (1)
108-114: providerId = null 처리 — 영향 검증 결과
- 결론: 탈퇴 시 providerId를 null로 설정하는 접근은 재가입 허용/유니크 충돌 회피 목적에 부합.
- 코드베이스 확인: providerId 기반 조회는 UserRepository#findByProviderAndProviderId(Provider,String) 선언 및 UserCommandServiceImpl.isnewUser(...)에서 호출(컨트롤러·테스트 포함). 캐시/세션/토큰을 providerId 키로 사용하는 코드는 발견되지 않음.
- 주의: User 엔티티에 (provider, providerId) 복합 unique 제약 선언이 있음 (src/main/java/stackpot/stackpot/user/entity/User.java). DB 엔진별로 NULL 취급이 달라 중복 허용/불허 결과가 달라질 수 있으므로 운영 DB에서 UNIQUE+NULL 동작을 확인하세요. 필요 시 Provider.UNKNOWN 정규화 또는 탈퇴 시 고유 placeholder 삽입 방안 검토.
- 권고 실행항목: 1) 운영 DB의 UNIQUE+NULL 동작 확인 2) 분석/통계 파이프라인의 혼선 여부 점검 3) 운영환경에서 캐시/외부시스템의 providerId 키 사용 여부 재확인.
| @Column(nullable = true) | ||
| private String providerId; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
DB 스키마(컬럼 NOT NULL 해제) 마이그레이션 없으면 런타임 장애 발생
엔티티에서 providerId를 nullable로 바꿨지만, 실제 DB 컬럼이 아직 NOT NULL이면 deleteUser()에서 null로 세팅 후 flush 시 제약 위반이 납니다. 배포 전에 반드시 스키마 마이그레이션과 데이터 백필을 포함하세요.
- 스키마:
providerId의 NOT NULL 제거 - 데이터: 과거 이미 탈퇴된(
is_deleted = true) 레코드의providerId도NULL로 백필
또한 복합 유니크(테이블 수준 uk_provider_provider_id: provider, providerId)와의 상호작용을 DB별로 확인 필요합니다. 다수 DB(MySQL, PostgreSQL)는 NULL을 유니크 비교에서 제외하지만, DB 방언에 따라 동작이 다를 수 있습니다. 운영 DB 방언을 확인하고 필요시 “활성 사용자만” 유니크가 적용되도록 부분(필터드) 인덱스/제약으로 보완을 검토하세요.
예시(실 DB/네이밍 전략에 맞게 조정):
- MySQL
ALTER TABLE user MODIFY COLUMN provider_id VARCHAR(255) NULL;UPDATE user SET provider_id = NULL WHERE is_deleted = 1;
- PostgreSQL
ALTER TABLE "user" ALTER COLUMN "providerId" DROP NOT NULL;UPDATE "user" SET "providerId" = NULL WHERE is_deleted = true;
다음 스크립트로 레포 내 마이그레이션 도입 여부와 관련 변경이 포함됐는지 빠르게 점검해 주세요(루트에서 실행).
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Detect migration framework (Flyway/Liquibase) ==="
rg -nP --type pom --type gradle -C2 '(flyway|liquibase)'
echo
echo "=== List candidate migration files ==="
fd -HI -t f 'db/migration' || true
fd -HI -t f 'db/changelog' || true
fd -HI -t f 'changelog.*\.(ya?ml|xml|sql)' || true
echo
echo "=== Search migrations touching providerId/provider_id ==="
rg -nP -C2 '\b(providerId|provider_id)\b' --type sql --type xml --type yml --type yaml || trueLength of output: 81
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Detecting Flyway/Liquibase references ==="
rg -n --hidden -S --no-ignore '(?i)\b(flyway|liquibase)\b' || true
echo
echo "=== Show top-level build files (if present) ==="
for f in pom.xml build.gradle build.gradle.kts settings.gradle settings.gradle.kts gradle.properties gradlew; do
if [ -f "$f" ]; then
echo "---- $f ----"
sed -n '1,200p' "$f"
echo
fi
done
echo
echo "=== Candidate migration directories (common paths) ==="
for d in src/main/resources/db/migration src/main/resources/db/changelog db/migration db/changelog migrations src/main/resources/migrations; do
if [ -d "$d" ]; then
echo "---- $d ----"
find "$d" -maxdepth 3 -type f -print
echo
fi
done
echo
echo "=== List migration-like files anywhere (sql/yml/xml) ==="
rg -n --hidden -S --no-ignore --glob '!**/target/**' -g '**/db/**' -g '**/migrations/**' -g '**/changelog/**' -g '*.sql' -g '*.yml' -g '*.yaml' -g '*.xml' '.*' || true
echo
echo "=== Search for providerId/provider_id occurrences ==="
rg -n --hidden -S --no-ignore '\b(providerId|provider_id)\b' || true
echo
echo "=== Search for ALTER TABLE / DROP NOT NULL / MODIFY COLUMN patterns in SQL/YAML/XML ==="
rg -n --hidden -S --no-ignore '(ALTER TABLE|DROP NOT NULL|MODIFY COLUMN|DROP NOT NULL|SET NULL|NULL;)' -g '*.sql' -g '*.xml' -g '*.yml' -g '*.yaml' || trueLength of output: 23423
긴급: DB 마이그레이션 추가 필요 (providerId NULL 허용)
엔티티에서 providerId를 nullable로 변경했고 delete 흐름에서 this.providerId = null로 설정하지만, 레포에서 관련 스키마/데이터 마이그레이션(또는 Flyway/Liquibase 의존성)이 발견되지 않았습니다. 운영 DB가 아직 NOT NULL이면 flush 시 제약 위반으로 서비스 장애가 발생합니다.
조치 (필수)
- 스키마 마이그레이션 추가: user 테이블의 provider_id(또는 providerId) 컬럼 NOT NULL 제거.
- MySQL 예: ALTER TABLE user MODIFY COLUMN provider_id VARCHAR(255) NULL;
- PostgreSQL 예: ALTER TABLE "user" ALTER COLUMN "providerId" DROP NOT NULL;
- 데이터 백필: 이미 탈퇴(is_deleted = true)된 레코드의 provider_id를 NULL로 업데이트.
- 예: UPDATE user SET provider_id = NULL WHERE is_deleted = 1;
- 유니크 제약 검증: 테이블 유니크(uk_provider_provider_id: provider, providerId)의 NULL 취급을 운영 DB 방언별로 확인. 필요 시 “활성 사용자만” 적용되는 부분(필터드/부분) 인덱스 또는 제약으로 보완.
참고 위치
- 엔티티: src/main/java/stackpot/stackpot/user/entity/User.java — providerId 선언(약 L45) 및 삭제 처리(this.providerId = null, 약 L111).
- 레포 상태: build.gradle에 Flyway/Liquibase 없음, 레포 내 db/migration·changelog·ALTER TABLE 관련 마이그레이션 스크립트 미발견.
🤖 Prompt for AI Agents
In src/main/java/stackpot/stackpot/user/entity/User.java around lines 44-46 and
the delete handling around line 111, you changed providerId to nullable but did
not add DB migrations; add a schema migration script (Flyway or Liquibase) that
alters the user table to make provider_id nullable (MySQL: ALTER TABLE user
MODIFY COLUMN provider_id VARCHAR(255) NULL; PostgreSQL: ALTER TABLE "user"
ALTER COLUMN "providerId" DROP NOT NULL;), include a data-backfill step to set
provider_id = NULL for already-deleted rows (UPDATE user SET provider_id = NULL
WHERE is_deleted = true), and verify/update any unique constraint/index
(uk_provider_provider_id) to handle NULLs correctly (create a filtered/partial
unique index or change constraint to apply only to active users if necessary);
add the migration file to the repo and ensure the build includes and runs DB
migrations (add Flyway/Liquibase dependency and config if missing).
PR 타입(하나 이상의 PR 타입을 선택해주세요)
반영 브랜치
ex) feat/login -> dev
작업 내용
ex) 로그인 시, 구글 소셜 로그인 기능을 추가했습니다.
테스트 결과
ex) 베이스 브랜치에 포함되기 위한 코드는 모두 정상적으로 동작해야 합니다. 결과물에 대한 스크린샷, GIF, 혹은 라이브
Summary by CodeRabbit