Skip to content

Fix: Club 엔티티 연관관계 및 인덱스 정리#367

Merged
rlagkswn00 merged 2 commits intodevelopfrom
fix/issue-352-club-entity-migration
Mar 31, 2026
Merged

Fix: Club 엔티티 연관관계 및 인덱스 정리#367
rlagkswn00 merged 2 commits intodevelopfrom
fix/issue-352-club-entity-migration

Conversation

@rlagkswn00
Copy link
Copy Markdown
Member

@rlagkswn00 rlagkswn00 commented Mar 27, 2026

#️⃣ 이슈

📌 요약

  • Club과 ClubSns 연관관계에서 Club이 하위 엔티티 생명주기를 관리하도록 매핑을 정리했습니다.
  • club_subscribe 테이블의 중복 인덱스를 안전하게 제거하는 마이그레이션을 추가했습니다.

🛠️ 상세

  • Club.homepageUrls에 cascade = CascadeType.ALL과 orphanRemoval = true를 적용해 ClubSns가 부모 엔티티 기준으로 함께 관리되도록 수정했습니다.
  • information_schema.statistics를 조회한 뒤 조건부로 idx_club_subscribe_club 인덱스를 삭제하는 Flyway 마이그레이션을 추가했습니다.
  • 인덱스가 이미 없는 환경에서도 실패하지 않도록 동적 SQL 방식으로 처리했습니다.

💬 기타

  • DB 마이그레이션이 포함되어 있으므로 배포 시 Flyway 적용 결과를 확인해야 합니다.
  • ClubSns 삭제 전파와 orphan removal이 의도한 동작과 일치하는지 통합 흐름에서 한 번 더 확인하는 것이 좋습니다.

Summary by CodeRabbit

릴리스 노트

  • 버그 수정

    • 클럽 웹사이트 URL 데이터 관리의 일관성 및 안정성 개선
  • 데이터베이스

    • 중복 인덱스를 정리하는 마이그레이션으로 데이터베이스 성능 최적화
  • 테스트

    • 클럽 데이터 생명 주기 관리 안정성 검증 테스트 추가

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

Walkthrough

Club 엔티티의 homepageUrls 필드의 JPA @OneToMany 매핑 설정을 업데이트하여 cascade = CascadeType.ALLorphanRemoval = true를 추가하고, 중복 인덱스를 제거하는 데이터베이스 마이그레이션을 추가하며, 이를 검증하는 테스트를 작성했습니다.

Changes

Cohort / File(s) Summary
JPA 관계 설정 업데이트
src/main/java/com/kustacks/kuring/club/domain/Club.java
homepageUrls 필드의 @OneToMany 애노테이션에 cascade = CascadeType.ALLorphanRemoval = true를 추가하여 자동 캐스케이딩 및 고아 제거 처리 기능을 활성화했습니다.
데이터베이스 마이그레이션
src/main/resources/db/migration/V260326__Drop_duplicate_club_subscribe_index.sql
조건부로 club_subscribe 테이블의 중복 인덱스 idx_club_subscribe_club을 제거하는 SQL 마이그레이션을 추가했습니다.
테스트 추가
src/test/java/com/kustacks/kuring/club/domain/ClubTest.java
homepageUrls 필드의 @OneToMany 애노테이션이 orphanRemoval = trueCascadeType.ALL을 올바르게 설정했는지 검증하는 테스트를 작성했습니다.

Possibly related issues

Possibly related PRs

Suggested labels

🐛 Bug

Poem

🐰 오류를 잡아 고치는 날,
캐스케이드가 흐르고 고아들을 돌보고,
인덱스는 정리되고 테스트가 우릴 증명하네,
데이터의 일관성과 함께 춤춘다네! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly describes the main changes: fixing Club entity relationships and cleaning up the index, which directly aligns with the cascade/orphanRemoval configuration update and database migration.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-352-club-entity-migration

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
Copy Markdown

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

🧹 Nitpick comments (2)
src/main/resources/db/migration/V260326__Drop_duplicate_club_subscribe_index.sql (1)

11-11: 인덱스 제거 후 조회 성능 회귀 여부만 배포 단계에서 확인해 주세요.

club_subscribeclub_id 조건 조회가 많은 경우, 배포 후 주요 쿼리에 대해 EXPLAIN으로 실행 계획을 한 번 점검해 두면 안전합니다.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/resources/db/migration/V260326__Drop_duplicate_club_subscribe_index.sql`
at line 11, 이 변경은 'ALTER TABLE club_subscribe DROP INDEX
idx_club_subscribe_club'로 인덱스를 제거하므로 배포 전/후 주요 club_id 사용 쿼리들의 실행 계획과 비용을
EXPLAIN으로 비교해 성능 회귀 여부를 확인하세요; 만약 조회 성능이 악화되면 idx_club_subscribe_club을 유지하거나 더
적합한 인덱스(예: 조건에 맞춘 복합 인덱스)로 교체하도록 SQL을 준비하고, 배포 계획에 롤백/재생성 절차를 포함시켜 주세요.
src/test/java/com/kustacks/kuring/club/domain/ClubTest.java (1)

16-25: 리플렉션 기반 테스트는 어노테이션 설정만 검증하며, 실제 JPA 동작을 검증하지 않습니다.

현재 테스트는 @OneToMany 어노테이션의 속성 값을 검증하지만, 실제 orphan removal 및 cascade 동작은 검증하지 않습니다. PR 설명에서 언급된 대로, ClubSns 삭제 전파와 orphan removal이 의도대로 동작하는지 통합 테스트로 검증하는 것을 권장합니다.

또한 NoSuchFieldException을 throws로 선언하면 필드명이 변경될 때 assertion 실패가 아닌 예외가 발생합니다.

♻️ 예외 처리 개선 제안
 `@Test`
 `@DisplayName`("homepageUrls는 Club이 ClubSns 생명주기를 관리하도록 설정된다")
-void homepage_urls_should_manage_club_sns_lifecycle() throws NoSuchFieldException {
-    Field homepageUrlsField = Club.class.getDeclaredField("homepageUrls");
+void homepage_urls_should_manage_club_sns_lifecycle() {
+    Field homepageUrlsField;
+    try {
+        homepageUrlsField = Club.class.getDeclaredField("homepageUrls");
+    } catch (NoSuchFieldException e) {
+        throw new AssertionError("Club 엔티티에 homepageUrls 필드가 존재하지 않습니다", e);
+    }
     OneToMany mapping = homepageUrlsField.getAnnotation(OneToMany.class);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/com/kustacks/kuring/club/domain/ClubTest.java` around lines 16
- 25, The reflection-based test in ClubTest only inspects the `@OneToMany`
annotation (homepageUrlsField / OneToMany) and doesn't verify runtime JPA
behavior for cascade/orphanRemoval; replace or supplement this unit test with an
integration test that persists a Club with associated ClubSns entities, deletes
or removes a ClubSns and verifies the deletion is propagated (cascade remove)
and that orphan removal actually deletes the child from the DB, invoking real
EntityManager/Repository operations; also remove the "throws
NoSuchFieldException" pattern on the test (currently declared on
homepage_urls_should_manage_club_sns_lifecycle) and instead handle failures with
assertions so a renamed/removed field produces a test failure rather than an
unchecked exception.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/main/resources/db/migration/V260326__Drop_duplicate_club_subscribe_index.sql`:
- Line 11: 이 변경은 'ALTER TABLE club_subscribe DROP INDEX
idx_club_subscribe_club'로 인덱스를 제거하므로 배포 전/후 주요 club_id 사용 쿼리들의 실행 계획과 비용을
EXPLAIN으로 비교해 성능 회귀 여부를 확인하세요; 만약 조회 성능이 악화되면 idx_club_subscribe_club을 유지하거나 더
적합한 인덱스(예: 조건에 맞춘 복합 인덱스)로 교체하도록 SQL을 준비하고, 배포 계획에 롤백/재생성 절차를 포함시켜 주세요.

In `@src/test/java/com/kustacks/kuring/club/domain/ClubTest.java`:
- Around line 16-25: The reflection-based test in ClubTest only inspects the
`@OneToMany` annotation (homepageUrlsField / OneToMany) and doesn't verify runtime
JPA behavior for cascade/orphanRemoval; replace or supplement this unit test
with an integration test that persists a Club with associated ClubSns entities,
deletes or removes a ClubSns and verifies the deletion is propagated (cascade
remove) and that orphan removal actually deletes the child from the DB, invoking
real EntityManager/Repository operations; also remove the "throws
NoSuchFieldException" pattern on the test (currently declared on
homepage_urls_should_manage_club_sns_lifecycle) and instead handle failures with
assertions so a renamed/removed field produces a test failure rather than an
unchecked exception.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ad148ed7-4fd1-48de-b9c2-9bbfd62ada48

📥 Commits

Reviewing files that changed from the base of the PR and between c55817f and 5915843.

📒 Files selected for processing (3)
  • src/main/java/com/kustacks/kuring/club/domain/Club.java
  • src/main/resources/db/migration/V260326__Drop_duplicate_club_subscribe_index.sql
  • src/test/java/com/kustacks/kuring/club/domain/ClubTest.java

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

Unit Test Results

  84 files  ±0    84 suites  ±0   1m 37s ⏱️ -3s
597 tests ±0  590 ✔️ ±0  7 💤 ±0  0 ±0 
600 runs  ±0  593 ✔️ ±0  7 💤 ±0  0 ±0 

Results for commit 2cdd2d1. ± Comparison against base commit c55817f.

♻️ This comment has been updated with latest results.

@rlagkswn00 rlagkswn00 self-assigned this Mar 28, 2026
@rlagkswn00 rlagkswn00 added the 🔥 Enhancement New feature or request label Mar 28, 2026
@jiyun921
Copy link
Copy Markdown
Collaborator

수고하셨습니다!! 변경사항 확인했습니당

Copy link
Copy Markdown
Member

@kimjuneon kimjuneon left a comment

Choose a reason for hiding this comment

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

확인했습니다 수고하셨습니다!

@rlagkswn00 rlagkswn00 merged commit 4bb3ecc into develop Mar 31, 2026
4 checks passed
@rlagkswn00
Copy link
Copy Markdown
Member Author

close #352

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

Labels

🔥 Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants