Skip to content

Conversation

@whqtker
Copy link
Member

@whqtker whqtker commented Feb 10, 2026

관련 이슈

작업 내용

기존에는 true, false 로 현재 학기를 구분했는데, 'true가 단 하나여야 한다'는 조건을 만족하지 않습니다. true 만 단 하나가 존재하기 위해서 함수형 인덱스를 설정하는 것은 복잡하고, flyway-jpa 간 매핑도 잘 되지 않기 때문에 필드에 UK만 설정하고, 기존에 false 였던 값을 null로 바꾸도록 수정했습니다.


추가로 미사용 도메인 메서드를 제거했습니다. 어드민에서 현재 학기 변경할 때 사용될 수 있지만, 해당 기능 구현할 때 작성하겠습니다.

특이 사항

리뷰 요구사항 (선택)

@whqtker whqtker self-assigned this Feb 10, 2026
@whqtker whqtker added the 버그 Something isn't working label Feb 10, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

Walkthrough

  1. 도메인 모델 변경. Term.java에서 isCurrent 필드가 원시 boolean에서 박스형 Boolean으로 변경되었습니다.
  2. 생성자 및 초기화 변경. 생성자는 입력이 true일 때만 isCurrenttrue로 설정하고, 그렇지 않으면 null로 설정하도록 수정되었습니다.
  3. 데이터베이스 제약 변경. 엔티티의 컬럼 설정에서 nullable = false가 제거되고 unique = true 제약이 추가되었으며, 관련 마이그레이션(V46)이 추가되었습니다.
  4. 테스트 데이터 수정. 멘토 조회 및 마이페이지 테스트에서 기준 학기가 "2025-2"에서 "2025-1"로 변경되었습니다.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

Suggested reviewers

  • wibaek
  • Gyuhyeok99
  • lsy1307
  • Hexeong
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 풀 리퀘스트 제목이 주요 변경사항을 명확하게 요약하고 있습니다. 'term 테이블의 is_current 필드에 UK 설정'은 핵심 변경사항을 정확히 반영합니다.
Description check ✅ Passed PR 설명이 필수 템플릿 항목을 충족하고 있으며, 작업 내용과 변경 이유를 상세히 설명하고 있습니다.
Linked Issues check ✅ Passed PR의 모든 코드 변경사항이 #597 이슈의 요구사항을 충족합니다. 유니크 키 설정과 false 값을 null로 변경하여 데이터 무결성을 보장합니다.
Out of Scope Changes check ✅ Passed 테스트 파일의 학기 변경(2025-2 → 2025-1)은 마이그레이션에 맞춰 기존 테스트 데이터를 업데이트하는 것으로 범위 내 변경입니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/com/example/solidconnection/term/domain/Term.java (1)

18-18: ⚠️ Potential issue | 🟠 Major

@AllArgsConstructor를 제거하여 null 변환 로직 우회 방지

현재 코드에서 @AllArgsConstructor가 Term(Long id, String name, Boolean isCurrent) 3개 인자 생성자를 자동 생성하고 있습니다. 이는 37-40번 줄의 커스텀 생성자에서 구현한 false → null 변환 로직을 완전히 우회할 수 있습니다.

  1. 발견된 문제

    • @AllArgsConstructor의 3인자 생성자로 new Term(1L, "name", false)를 호출하면 isCurrentfalse가 그대로 저장됨
    • 34번 줄의 unique 제약에 의해 false 값이 하나만 허용되어 의도하지 않은 제약 위반 발생 가능
  2. 현재 상태

    • 코드베이스에서는 2인자 생성자(new Term(name, isCurrent))만 사용 중
    • 3인자 생성자 직접 호출은 없음
  3. 권장 조치

    • @AllArgsConstructor 제거 (34번 줄 삭제)
    • 2인자 커스텀 생성자와 setter 메서드만으로 충분
🔧 제안: `@AllArgsConstructor` 제거
 `@Getter`
 `@NoArgsConstructor`(access = AccessLevel.PROTECTED)
 `@Entity`
-@AllArgsConstructor
 `@Table`(uniqueConstraints = {
         `@UniqueConstraint`(
                 name = "uk_term_name",
                 columnNames = {"name"}
         )
 })
 public class Term {
🤖 Fix all issues with AI agents
In `@src/main/java/com/example/solidconnection/term/domain/Term.java`:
- Around line 42-48: The setAsCurrent()/setAsNotCurrent() pair is fine but must
be used atomically to avoid UNIQUE constraint violations: implement a
transactional service method (e.g., in TermService) that locates the existing
current Term (using the repository method that queries isCurrent), calls
existingTerm.setAsNotCurrent(), then targetTerm.setAsCurrent(), and saves both
within the same `@Transactional` boundary; ensure you use the repository query
(e.g., findByIsCurrentTrue or equivalent) and persist the changes in the same
transaction so the UNIQUE constraint on isCurrent is never violated.

In
`@src/main/resources/db/migration/V45__add_unique_constraint_to_term_is_current.sql`:
- Around line 1-9: 현재 마이그레이션은 term 테이블의 is_current 컬럼에 유니크
제약(uk_term_is_current)을 바로 추가하는데, 사전 검증 없이 동일한 is_current = TRUE 레코드가 2개 이상이면 제약
추가 시 실패합니다; 따라서 V45 마이그레이션에 제약 추가 전에 term 테이블의 is_current가 TRUE인 레코드가 여러 개인지
검사하고(또는 SELECT로 확인한 뒤) 하나만 유지하고 나머지는 NULL로 보정하는 방어 로직을 추가하여 ADD CONSTRAINT
uk_term_is_current 실행 전 데이터 정합성을 보장하세요(대상 식별에 사용할 고유키/updated_at/우선순위 기준을 명시해
하나만 남기도록 업데이트).

Copy link

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/com/example/solidconnection/term/domain/Term.java (1)

18-18: ⚠️ Potential issue | 🟠 Major

@AllArgsConstructorisCurrent 변환 로직을 우회할 수 있습니다.

  1. @AllArgsConstructorTerm(Long id, String name, Boolean isCurrent) 생성자를 자동 생성합니다.
  2. 이 생성자는 Line 39의 isCurrent ? true : null 변환 로직을 거치지 않습니다.
  3. 따라서 new Term(1L, "2025-1", false)를 호출하면 false가 그대로 DB에 저장되어, null 기반 UNIQUE 제약 설계 의도가 무너질 수 있습니다.

@AllArgsConstructor를 제거하거나, 테스트 전용이라면 접근 수준을 제한하는 것을 권장합니다.

♻️ 수정 제안
-@AllArgsConstructor

만약 테스트 등에서 all-args 생성자가 필요하다면, AccessLevel.PRIVATE으로 제한하세요:

-@AllArgsConstructor
+@AllArgsConstructor(access = AccessLevel.PRIVATE)

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

Labels

버그 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: term 테이블의 is_current 필드는 단 하나의 레코드만 true여야 한다.

1 participant