Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/stackpot/stackpot/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class User extends BaseEntity implements UserDetails{
@Enumerated(EnumType.STRING)
private Provider provider;

@Column(nullable = false)
@Column(nullable = true)
private String providerId;

Comment on lines +44 to 46
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

🧩 Analysis chain

DB 스키마(컬럼 NOT NULL 해제) 마이그레이션 없으면 런타임 장애 발생

엔티티에서 providerId를 nullable로 바꿨지만, 실제 DB 컬럼이 아직 NOT NULL이면 deleteUser()에서 null로 세팅 후 flush 시 제약 위반이 납니다. 배포 전에 반드시 스키마 마이그레이션과 데이터 백필을 포함하세요.

  • 스키마: providerId의 NOT NULL 제거
  • 데이터: 과거 이미 탈퇴된(is_deleted = true) 레코드의 providerIdNULL로 백필

또한 복합 유니크(테이블 수준 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 || true

Length 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' || true

Length 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).

@Column(nullable = false)
Expand Down Expand Up @@ -108,7 +108,7 @@ public Long getUserId() {
public void deleteUser() {
this.isDeleted = true;
this.nickname = "(알 수 없음)"; // 표시용 변경

this.providerId = null;
if (this.roles != null) {
this.roles.clear(); // 기존 역할 초기화
}
Expand Down