-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: 잘못 설정되었던 테이블 간 연관 관계 재설정 #622
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
refactor: 잘못 설정되었던 테이블 간 연관 관계 재설정 #622
Conversation
Walkthrough
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/main/resources/data.sql (1)
151-226: 2) university_info_for_apply 시드에 home_university_id가 비어 있습니다.
- 새 FK 관계를 테스트/개발 환경에서 검증하려면 시드에 home_university_id 값이 필요할 수 있습니다.
- 의도적으로 NULL 유지라면 괜찮지만, 관계 사용 코드가 있다면 시드 보완을 권장합니다.
src/main/java/com/example/solidconnection/university/domain/UnivApplyInfo.java (1)
24-27: @EqualsAndHashCode의 callSuper를 명시적으로 지정해주세요.BaseEntity를 상속받은 클래스이기 때문에 CI 경고가 발생하고 있습니다. 의도를 명확히 하기 위해 callSuper 값을 명시적으로 지정해 경고를 해결하세요.
@EqualsAndHashCode주석 수정
- 현재:
@EqualsAndHashCode(of = "id")- 변경:
@EqualsAndHashCode(of = "id", callSuper = false)- 이유: id만으로 엔티티의 동등성을 정의하고, 부모 클래스의 감시 필드(createdAt, updatedAt)는 제외합니다.
🔧 제안 수정
-@EqualsAndHashCode(of = "id") +@EqualsAndHashCode(of = "id", callSuper = false)
🤖 Fix all issues with AI agents
In
`@src/main/resources/db/migration/V43__move_home_university_fk_to_univ_apply_info.sql`:
- Around line 1-12: The migration drops fk_host_university_home_university and
host_university.home_university_id without backfilling, which will lose data;
instead: add the new nullable column
university_info_for_apply.home_university_id, copy values from
host_university.home_university_id into university_info_for_apply (using the
appropriate join on the linking key between host_university and
university_info_for_apply), then add the new FK
fk_university_info_for_apply_home_university, verify data, and only after
successful backfill drop the old foreign key fk_host_university_home_university
and drop host_university.home_university_id; ensure the copy handles NULLs and
preserves referential integrity before removing the original constraint.
| ALTER TABLE host_university | ||
| DROP FOREIGN KEY fk_host_university_home_university; | ||
|
|
||
| ALTER TABLE host_university | ||
| DROP COLUMN home_university_id; | ||
|
|
||
| ALTER TABLE university_info_for_apply | ||
| ADD COLUMN home_university_id BIGINT NULL; | ||
|
|
||
| ALTER TABLE university_info_for_apply | ||
| ADD CONSTRAINT fk_university_info_for_apply_home_university | ||
| FOREIGN KEY (home_university_id) REFERENCES home_university (id) ON DELETE NO ACTION; |
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.
1) 데이터 이관 없이 컬럼을 드롭하면 기존 관계가 소실됩니다.
- 현재 스크립트는 기존 home_university_id 값을 백필하지 않고 컬럼을 제거합니다.
- 운영 데이터가 있다면 FK 이동 과정에서 값이 유실됩니다.
🛠️ 안전한 순서 예시
-ALTER TABLE host_university
- DROP FOREIGN KEY fk_host_university_home_university;
-
-ALTER TABLE host_university
- DROP COLUMN home_university_id;
-
-ALTER TABLE university_info_for_apply
- ADD COLUMN home_university_id BIGINT NULL;
-
-ALTER TABLE university_info_for_apply
- ADD CONSTRAINT fk_university_info_for_apply_home_university
- FOREIGN KEY (home_university_id) REFERENCES home_university (id) ON DELETE NO ACTION;
+ALTER TABLE university_info_for_apply
+ ADD COLUMN home_university_id BIGINT NULL;
+
+UPDATE university_info_for_apply u
+JOIN host_university h ON u.university_id = h.id
+SET u.home_university_id = h.home_university_id;
+
+ALTER TABLE university_info_for_apply
+ ADD CONSTRAINT fk_university_info_for_apply_home_university
+ FOREIGN KEY (home_university_id) REFERENCES home_university (id) ON DELETE NO ACTION;
+
+ALTER TABLE host_university
+ DROP FOREIGN KEY fk_host_university_home_university;
+
+ALTER TABLE host_university
+ DROP COLUMN home_university_id;🤖 Prompt for AI Agents
In
`@src/main/resources/db/migration/V43__move_home_university_fk_to_univ_apply_info.sql`
around lines 1 - 12, The migration drops fk_host_university_home_university and
host_university.home_university_id without backfilling, which will lose data;
instead: add the new nullable column
university_info_for_apply.home_university_id, copy values from
host_university.home_university_id into university_info_for_apply (using the
appropriate join on the linking key between host_university and
university_info_for_apply), then add the new FK
fk_university_info_for_apply_home_university, verify data, and only after
successful backfill drop the old foreign key fk_host_university_home_university
and drop host_university.home_university_id; ensure the copy handles NULLs and
preserves referential integrity before removing the original constraint.
관련 이슈
작업 내용
이전에
home_university와host_university와 잘못 연관관계 설정되었던 부분을 수정했습니다.특이 사항
리뷰 요구사항 (선택)