Skip to content

[FIX] gameResult, room 테이블 수정#101

Merged
hjh79gw merged 2 commits intodevfrom
FIX-방삭제
Dec 23, 2025

Hidden character warning

The head ref may contain hidden characters: "FIX-\ubc29\uc0ad\uc81c"
Merged

[FIX] gameResult, room 테이블 수정#101
hjh79gw merged 2 commits intodevfrom
FIX-방삭제

Conversation

@ochanhyeok
Copy link
Collaborator

@ochanhyeok ochanhyeok commented Dec 23, 2025

📌 작업 내용

방삭제를 위한 테이블 관계 재설정


🔗 관련 이슈

  • closes #

👀 리뷰 시 참고사항

  • 리뷰어가 중점적으로 보면 좋을 부분을 작성해 주세요.
  • 고민한 지점이나 피드백 받고 싶은 부분이 있다면 함께 남겨주세요.

💭 느낀 점

  • 작업하면서 느낀 점이나 공유하고 싶은 내용을 자유롭게 작성해 주세요.

💻 스크린샷 (선택)

  • 필요한 경우 첨부해 주세요.

Summary by CodeRabbit

릴리스 노트

  • 버그 수정

    • 게임 상태 전환 중 더 정확한 추적으로 연결 안정성 개선
    • 플레이어 수 제한 강제로 멀티플레이 무결성 강화
    • 플레이어 연결 해제 시 게임 상태 자동 초기화
    • 방 삭제 시 데이터 정리 프로세스 개선
  • 리팩토링

    • 게임 흐름 모니터링을 위한 상세 로깅 추가

✏️ Tip: You can customize this high-level summary in your review settings.

@ochanhyeok ochanhyeok self-assigned this Dec 23, 2025
@ochanhyeok ochanhyeok added the FIX 버그 수정 label Dec 23, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 23, 2025

워크스루

게임 룸의 생명주기를 관리하기 위해 로깅 강화, 플레이어 연결/종료 시 상태 추적, 마지막 플레이어 퇴장 시 게임 룸 삭제 처리를 추가했습니다. 데이터베이스 마이그레이션을 통해 외래 키 제약 조건을 제거하고 특수 룸 ID를 초기화했습니다.

변경사항

집단 / 파일 변경 요약
게임 서비스 로깅 및 상태 관리
src/main/java/game/single/service/SingleGameServiceImpl.java
연결 개시(onOpen), 메시지 수신(onMessage), 연결 종료(onClose) 단계에서 상세 로깅 추가. 2인 플레이 제한 강제 및 거부 시 세션 종료. 턴 검증 로직 추가. 플레이어 퇴장 시 활성 플레이어 0명일 경우 보드, 턴, gameOver, 패스 상태 초기화 및 타이머 취소 처리 추가.
룸 서비스 삭제 처리
src/main/java/room/service/RoomService.java
DELETED_ROOM_ID 상수 도입. 삭제된 룸 감지 후 가드 체크 추가. 마지막 활성 참가자 퇴장 시 game_result.room_id를 DELETED_ROOM_ID로 업데이트 후 room_player 및 room 행 삭제. 기존 호스트 이전 로직 유지.
데이터베이스 마이그레이션
src/main/resources/db/migration/V7__alter_gameresult.sql
src/main/resources/db/migration/V8__insert_room.sql
V7: game_result 테이블의 FK_GAME_RESULT_ROOM 외래 키 제약 조건 제거. V8: UUID 00000000-0000-0000-0000-000000000000인 룸 레코드 삭제.

예상 코드 리뷰 소요 시간

🎯 3 (보통) | ⏱️ ~20분

추천 검토자

  • hjh79gw
  • cl-o-lc

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목은 변경사항의 주요 목적(gameResult, room 테이블 수정 및 방 삭제 기능 구현)을 명확하게 반영합니다.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch FIX-방삭제

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

Copy link
Collaborator

@hjh79gw hjh79gw left a comment

Choose a reason for hiding this comment

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

고생하셨습니다

Copy link
Collaborator

@cl-o-lc cl-o-lc left a comment

Choose a reason for hiding this comment

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

수고하셨습니다👍

@hjh79gw hjh79gw merged commit ba857b5 into dev Dec 23, 2025
3 of 4 checks passed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
src/main/java/room/service/RoomService.java (2)

97-110: 이미 삭제된 방에 대한 방어 로직이 적절합니다.

동시성 환경에서 방이 이미 삭제된 경우를 처리하는 가드 로직이 올바르게 구현되었습니다.

다만, 처음부터 존재하지 않았던 잘못된 roomId와 동시에 삭제된 방을 구분할 수 없습니다. 필요하다면 추가 로깅이나 메트릭을 고려할 수 있습니다.


122-123: 로깅 프레임워크 사용을 고려하세요.

현재 System.out.println을 사용한 로깅은 다음과 같은 제한이 있습니다:

  • 로그 레벨 제어 불가 (DEBUG, INFO, ERROR 등)
  • 로그 파일 관리 및 로테이션 어려움
  • 성능 영향 (동기 I/O)

SLF4J, Log4j2 등의 로깅 프레임워크 사용을 권장합니다. 또한 사용자 ID와 방 ID가 PII에 해당할 수 있으므로 로깅 정책을 확인하세요.

Also applies to: 126-126, 148-148, 157-157, 173-173

src/main/java/game/single/service/SingleGameServiceImpl.java (2)

52-65: 연결 처리 로깅이 상세하게 추가되었습니다.

플레이어 연결 시 roomId, userId, 현재 플레이어 수 등을 로깅하여 디버깅에 유용합니다. 다만 각 연결마다 여러 로그 문이 실행되므로, 운영 환경에서는 로그 레벨을 고려하거나 일부 로그를 통합하는 것을 권장합니다.


137-147: 턴 검증 로직에 상세한 로깅이 추가되었습니다.

현재 턴 인덱스, 세션 ID 비교 등을 로깅하여 턴 관련 버그 추적에 유용합니다. 다만 로그가 매우 상세하므로, 운영 환경에서는 DEBUG 레벨로 설정하는 것을 고려하세요.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 58d8ae0 and 45fbfad.

📒 Files selected for processing (4)
  • src/main/java/game/single/service/SingleGameServiceImpl.java
  • src/main/java/room/service/RoomService.java
  • src/main/resources/db/migration/V7__alter_gameresult.sql
  • src/main/resources/db/migration/V8__insert_room.sql
🧰 Additional context used
🧬 Code graph analysis (2)
src/main/java/room/service/RoomService.java (1)
src/main/webapp/static/room/room.js (1)
  • roomId (3-3)
src/main/java/game/single/service/SingleGameServiceImpl.java (1)
src/main/webapp/static/room/room.js (1)
  • roomId (3-3)
🔇 Additional comments (6)
src/main/java/room/service/RoomService.java (3)

76-80: SQL 쿼리 구조가 올바릅니다.

게임 결과의 room_idDELETED_ROOM_ID로 업데이트하는 쿼리 로직이 정확합니다. V8 마이그레이션이 수정되어 더미 방이 존재한다면 의도대로 동작할 것입니다.


152-158: 게임 결과 업데이트 로직이 올바른 순서로 구현되었습니다.

방 삭제 전에 game_result.room_idDELETED_ROOM_ID로 업데이트하는 것은 참조 무결성을 유지하기 위한 올바른 접근입니다.

삭제 순서도 적절합니다:

  1. game_result.room_id 업데이트
  2. room_player 삭제
  3. room 삭제

V8 마이그레이션이 수정되어 더미 방이 존재한다면 의도대로 동작할 것입니다.


160-174: 방 삭제 시퀀스가 트랜잭션 내에서 올바르게 처리됩니다.

room_player 삭제 후 room 삭제하는 순서가 정확하며, 모든 작업이 성공한 후에만 커밋이 실행됩니다. 예외 발생 시 롤백 처리도 적절합니다.

src/main/java/game/single/service/SingleGameServiceImpl.java (2)

103-109: 게임 종료 상태 체크가 명시적으로 개선되었습니다.

메시지 처리 초반에 gameOver 상태를 명시적으로 확인하여 조기 반환하는 것은 좋은 방어 로직입니다. 게임이 이미 종료된 후 추가 메시지를 무시하여 일관성을 유지합니다.


210-218: 모든 플레이어 퇴장 시 게임 상태 리셋이 올바르게 구현되었습니다.

방이 비었을 때 게임 상태(board, turn, gameOver, passes)를 리셋하고 타이머를 취소하는 것은 방이 재사용될 경우를 대비한 중요한 로직입니다. 이는 RoomService의 방 삭제 처리와 잘 연계됩니다.

src/main/resources/db/migration/V7__alter_gameresult.sql (1)

1-2: 외래 키 제약 조건 제거에 대한 재검토 필요

game_resultroom 간의 외래 키 제약 조건을 삭제하면 데이터베이스 레벨의 참조 무결성 보장이 사라집니다. 다만, RoomService.exitAndHandleHost() 메서드에서 방 삭제 전에 관련된 모든 game_result 레코드의 room_id를 센티널 값(DELETED_ROOM_ID = "00000000-0000-0000-0000-000000000000")으로 변경하므로, 고아 레코드 생성은 방지되고 있습니다.

설계 의도가 명확하고 적절하게 구현되어 있으나, 이러한 패턴이 후속 유지보수에서도 일관되게 적용되도록 다음을 권고합니다:

  1. game_result.room_id가 실제 방 ID 또는 센티널 값만 가리키도록 보장
  2. 새로운 room 삭제 로직 추가 시에도 이 패턴 적용 확인
  3. V8 마이그레이션에서의 센티널 room 삭제는 적절함


private static final String STATUS_IN_ROOM = "0";
private static final String STATUS_EXIT = "2";
private static final String DELETED_ROOM_ID = "00000000-0000-0000-0000-000000000000";
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

DELETED_ROOM_ID 상수가 데이터베이스에 존재하는 더미 방을 전제로 합니다.

이 상수는 삭제된 방의 게임 결과를 보관하기 위한 플레이스홀더로 사용됩니다. 그러나 V8__insert_room.sql 마이그레이션이 현재 이 UUID의 방을 삭제하고 있어, 실제로는 존재하지 않는 방을 참조하게 됩니다.

V8 마이그레이션을 수정하여 이 UUID로 더미 방을 생성(INSERT)하도록 변경해야 합니다.

🤖 Prompt for AI Agents
In src/main/java/room/service/RoomService.java around line 13, the
DELETED_ROOM_ID constant (00000000-0000-0000-0000-000000000000) assumes a dummy
room exists in the DB but the V8__insert_room.sql migration currently deletes
that UUID; update the V8 migration to INSERT a dummy room row with this exact
UUID (populate required columns such as id, name, created_at, any non-nullable
fields and sensible defaults) so the constant points to a real record, and
ensure the migration runs before code that relies on the constant.

Comment on lines +1 to +4
DELETE
FROM room
WHERE id = '00000000-0000-0000-0000-000000000000';
COMMIT; No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

마이그레이션 로직이 커밋 메시지 및 의도와 불일치합니다.

커밋 메시지에서는 "삭제된 방의 전적을 보관할 더미 데이터 생성"이라고 명시했지만, 이 마이그레이션은 DELETE 문을 사용하여 해당 UUID의 방을 삭제하고 있습니다.

RoomService.java에서 방 삭제 시 game_result.room_idDELETED_ROOM_ID (동일한 UUID)로 업데이트하는데, 이 마이그레이션이 해당 방을 삭제하면 game_result 레코드들이 존재하지 않는 방을 참조하게 됩니다.

다음 중 하나로 수정이 필요합니다:

  1. DELETE 대신 INSERT 문을 사용하여 더미 방을 생성
  2. 또는 이미 더미 방이 존재한다면, 이 마이그레이션 파일 자체가 불필요
🔎 제안하는 수정 방안
-DELETE
-FROM room
-WHERE id = '00000000-0000-0000-0000-000000000000';
-COMMIT;
+INSERT INTO room (id, host_user_id, current_user_cnt, max_user_cnt, room_name, room_password, created_at)
+VALUES (
+  '00000000-0000-0000-0000-000000000000',
+  '00000000-0000-0000-0000-000000000000',
+  0,
+  0,
+  '[DELETED]',
+  NULL,
+  CURRENT_TIMESTAMP
+);
+COMMIT;

참고: host_user_id 및 기타 필수 컬럼에 대한 적절한 값을 설정해야 합니다.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
DELETE
FROM room
WHERE id = '00000000-0000-0000-0000-000000000000';
COMMIT;
INSERT INTO room (id, host_user_id, current_user_cnt, max_user_cnt, room_name, room_password, created_at)
VALUES (
'00000000-0000-0000-0000-000000000000',
'00000000-0000-0000-0000-000000000000',
0,
0,
'[DELETED]',
NULL,
CURRENT_TIMESTAMP
);
COMMIT;
🤖 Prompt for AI Agents
In src/main/resources/db/migration/V8__insert_room.sql lines 1-4, the migration
currently DELETEs the UUID used as DELETED_ROOM_ID, which contradicts the commit
message and breaks game_result references; replace the DELETE with an INSERT
that creates a dummy room row using that exact UUID and populate all NOT
NULL/required columns (host_user_id, name/title, created_at/updated_at,
status/visibility and any FKable fields) so existing game_result.room_id
references remain valid, then COMMIT; alternatively, if the dummy room already
exists in earlier migrations, remove this migration file entirely to avoid
redundant operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FIX 버그 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants