-
Notifications
You must be signed in to change notification settings - Fork 8
fix: BaseEntity 관련 마이그레이션 파일 수정 #530
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
fix: BaseEntity 관련 마이그레이션 파일 수정 #530
Conversation
Walkthrough
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
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: 0
🧹 Nitpick comments (1)
src/main/resources/db/migration/V34__add_baseentity_related_fields.sql (1)
1-194: 중복되는 컬럼 추가 로직을 공통화해 주세요.
- 중복 제거 제안
- 현재 테이블마다
SET @col_exists→PREPARE→EXECUTE→DEALLOCATE패턴을 반복하면서 스크립트가 길고 유지보수 비용이 높아졌습니다.- 테이블명과 컬럼명을 매개변수로 받아 처리하는 임시 프로시저(예:
CALL add_baseentity_columns('application'))를 정의·호출하면 가독성도 좋아지고, 추후 컬럼 정의가 바뀌어도 한 곳만 수정하면 됩니다.- Flyway에서는
CREATE PROCEDURE ...후 즉시CALL하고 마지막에DROP PROCEDURE하는 패턴을 지원하므로 구현 부담이 크지 않습니다.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/main/java/com/example/solidconnection/mentor/domain/Mentoring.java(0 hunks)src/main/resources/db/migration/V34__add_baseentity_related_fields.sql(1 hunks)
💤 Files with no reviewable changes (1)
- src/main/java/com/example/solidconnection/mentor/domain/Mentoring.java
c234aaf to
eaa8eb4
Compare
Hexeong
left a 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.
확인했습니다~ 늦은 시간에 수고 많으셨어요 :)
sukangpunch
left a 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.
고생하셨습니다!
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.
이거 이미 머지된 스크립트 파일 수정해도 되나요?
| ALTER TABLE gpa | ||
| ADD COLUMN created_at DATETIME(6), | ||
| ADD COLUMN updated_at DATETIME(6); | ||
|
|
||
| ALTER TABLE language_test | ||
| ADD COLUMN created_at DATETIME(6), | ||
| ADD COLUMN updated_at DATETIME(6); | ||
|
|
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.
@coderabbitai
이미 개발서버에 반영된 flaway 스크립트 파일 수정해도 문제 없는지 알려줘
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.
Flyway 마이그레이션 파일 수정 관련 답변
이미 개발 서버에 반영된 Flyway 스크립트를 수정하는 것은 일반적으로 권장되지 않습니다. 다음 이유들 때문입니다:
1. 체크섬 검증 실패 위험
Flyway는 각 마이그레이션 파일의 체크섬을 flyway_schema_history 테이블에 저장합니다. 이미 실행된 파일을 수정하면 체크섬이 달라져서 다음 배포 시 Flyway가 검증 오류를 발생시킵니다:
Validate failed: Migration checksum mismatch
2. 환경 간 불일치 문제
- 다른 개발자의 로컬 환경
- 스테이징 환경
- 프로덕션 환경
위 환경들과 동기화 문제가 발생할 수 있습니다.
3. 현재 PR의 접근 방식 분석
PR에서 수행하는 작업:
- ✅
flyway_schema_history에서 V34 레코드 삭제 - ✅
application테이블에서 컬럼 수동 삭제 - ✅ V34 파일 수정
이 방식은 개발 환경에서는 가능하지만 몇 가지 주의사항이 있습니다:
4. 권장 사항
옵션 A: 새로운 마이그레이션 생성 (권장)
-- V35__fix_baseentity_fields.sql
-- application 테이블 롤백
ALTER TABLE application DROP COLUMN created_at;
ALTER TABLE application DROP COLUMN updated_at;
-- 올바른 테이블에 적용
ALTER TABLE application ADD COLUMN created_at DATETIME(6);
ALTER TABLE application ADD COLUMN updated_at DATETIME(6);
-- ... 다른 테이블들옵션 B: 기존 파일 수정 (현재 PR 방식)
만약 V34를 수정해야 한다면:
필수 체크리스트:
- 모든 개발자의 로컬 DB를 리셋하거나 동일한 수동 작업 수행
- V34가 실행된 모든 환경(개발서버 등)에서 수동으로 rollback + history 삭제
- V34가 프로덕션에 반영되지 않았는지 확인
- 팀 전체에 공지
실행 순서:
-- 1. 각 환경에서 실행
DELETE FROM flyway_schema_history WHERE version = '34';
ALTER TABLE application DROP COLUMN IF EXISTS created_at;
ALTER TABLE application DROP COLUMN IF EXISTS updated_at;
-- 2. 그 후 수정된 V34 파일로 Flyway 재실행5. 주의사항
⚠️ 프로덕션에 이미 반영되었다면 절대 수정하지 마세요⚠️ 팀원들과 반드시 공유하고 조율하세요⚠️ 이 작업은 데이터 손실 위험이 있으니 백업을 권장합니다
결론
개발 서버에만 반영되었고 프로덕션에는 반영되지 않았다면, PR의 접근 방식도 가능합니다. 하지만 새로운 마이그레이션 파일(V35)을 생성하는 것이 더 안전하고 Flyway의 의도된 사용 방식입니다.
어떤 방식을 선택하시겠습니까?
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.
@whqtker 이거 확인 한 번 부탁드립니다
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.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
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.
@coderabbitai 애초에 V34 스크립트가 잘못되었기에(gpa 테이블은 존재하지 않음) V35 스크립트를 작성한다 한들, V34 적용 시 문제가 발생하고, V35는 적용되지 않는 거 아니니 ?
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.
@whqtker 정확한 지적입니다! 말씀하신 대로 V34가 실행 중 실패했기 때문에 V35로 해결할 수 없는 상황입니다.
상황 분석
문제점
- V34 스크립트가 존재하지 않는
gpa테이블에 대한 ALTER TABLE 구문을 포함 - Flyway가 V34 실행 중
gpa테이블에서 에러 발생 - V34가 실패 상태로
flyway_schema_history에 기록됨 (또는 부분적으로만 실행됨) - 이후 마이그레이션(V35, V36 등)은 실행되지 않음
V35 생성이 작동하지 않는 이유
V34 실행 → gpa 테이블 없음 → 실패 → STOP
↓
V35는 실행되지 않음
현재 PR의 접근 방식이 올바른 이유
말씀하신 것처럼 V34 자체를 수정하는 것이 유일한 해결책입니다:
수정된 V34의 내용
-- ❌ 제거: 존재하지 않는 테이블
-- ALTER TABLE gpa ...
-- ALTER TABLE language_test ...
-- ✅ 유지: 실제 존재하는 테이블들
ALTER TABLE application
ADD COLUMN created_at DATETIME(6),
ADD COLUMN updated_at DATETIME(6);
-- ✅ updated_at만 추가 (created_at는 이미 존재)
ALTER TABLE mentoring
ADD COLUMN updated_at DATETIME(6);
-- ... 나머지 테이블들필요한 작업 (PR에서 수행 중)
- ✅
flyway_schema_history에서 V34 레코드 삭제 - ✅
application테이블의created_at,updated_at수동 삭제 - ✅ V34 파일 수정 (gpa, language_test 제거)
- ✅ Flyway 재실행
결론
이전 답변에서 V35 생성을 권장했지만, V34가 실패한 상황에서는 V34 자체를 수정하는 것이 올바른 접근입니다. 제 답변이 현재 상황을 충분히 고려하지 못했습니다.
현재 PR의 접근 방식이 정확하며, 다음을 확인하시면 됩니다:
- 개발 서버에서 V34 관련 히스토리 삭제
-
application테이블 컬럼 수동 삭제 - 수정된 V34로 재실행
- 팀원들에게 동일한 작업 공유
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.
@coderabbitai 답변, PR 등을 고려하지 않고 오로지 현 문제에 초점을 맞췄을 때, 가장 현명한 해결 방법은 무엇인가 ?
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.
가장 현명한 해결 방법
오로지 기술적 관점에서 볼 때, 가장 깔끔한 해결 방법은 다음과 같습니다:
해결 전략: V34 수정 + Flyway Repair
1️⃣ 현재 상태 파악
-- flyway_schema_history 확인
SELECT version, description, type, script, checksum, installed_on, execution_time, success
FROM flyway_schema_history
WHERE version = '34';
-- application 테이블 구조 확인
DESCRIBE application;
-- mentoring 테이블 구조 확인
DESCRIBE mentoring;2️⃣ Flyway 상태 복구
# 옵션 A: Flyway repair 사용 (권장)
flyway repair
# 또는 옵션 B: 수동으로 히스토리 삭제
# DELETE FROM flyway_schema_history WHERE version = '34';Flyway repair가 하는 일:
- 실패한 마이그레이션 레코드 제거
- 체크섬 불일치 해결
- 누락된 마이그레이션 마커 제거
3️⃣ 부분 적용된 변경사항 롤백
-- application 테이블에만 추가된 컬럼 제거
ALTER TABLE application DROP COLUMN IF EXISTS created_at;
ALTER TABLE application DROP COLUMN IF EXISTS updated_at;4️⃣ V34 스크립트 수정
-- V34__add_baseentity_related_fields.sql
-- ❌ 제거: 존재하지 않는 테이블
-- ALTER TABLE gpa ...
-- ALTER TABLE language_test ...
ALTER TABLE application
ADD COLUMN created_at DATETIME(6),
ADD COLUMN updated_at DATETIME(6);
-- mentoring은 created_at가 이미 존재하므로 updated_at만 추가
ALTER TABLE mentoring
ADD COLUMN updated_at DATETIME(6);
-- ... 나머지 테이블들5️⃣ 마이그레이션 재실행
flyway migrate6️⃣ 검증
-- 모든 테이블에 컬럼이 올바르게 추가되었는지 확인
SELECT
TABLE_NAME,
COLUMN_NAME,
DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('created_at', 'updated_at')
AND TABLE_SCHEMA = DATABASE()
ORDER BY TABLE_NAME, COLUMN_NAME;왜 이 방법이 가장 현명한가?
✅ 장점
- 마이그레이션 히스토리가 깔끔함 - V34가 실제 의도대로 기록됨
- 재현 가능성 - 새로운 환경(로컬, CI/CD)에서 동일하게 작동
- Flyway 원칙 준수 - repair 명령어는 이런 상황을 위해 존재함
- 향후 문제 방지 - V35, V36 등이 정상적으로 실행됨
⚠️ 주의사항
- 프로덕션에 이미 배포되었다면 이 방법을 사용하면 안 됨 (데이터 보존 우선)
- 개발/스테이징 환경에서만 적용 가능
대안: 새로운 버전으로 보상 (프로덕션이 포함된 경우)
만약 프로덕션에도 V34가 부분적으로 적용되었다면:
-- V35__rollback_v34_and_fix.sql
-- 롤백
ALTER TABLE application DROP COLUMN IF EXISTS created_at;
ALTER TABLE application DROP COLUMN IF EXISTS updated_at;
-- V36__add_baseentity_fields_fixed.sql
-- 올바른 적용
ALTER TABLE application ADD COLUMN created_at DATETIME(6);
-- ... 나머지하지만 현재는 개발 서버만 영향받았으므로 V34 수정이 최선입니다.
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.
고생하셨습니다~
fix: PostRepository & CommentRepository의 일부 메서드의 정렬 순서 오류 해결 (#522) refactor: 이메일 유니크키 제거 refactor: 엔티티가 BaseEntity를 상속하도록 (#524) fix: BaseEntity 관련 마이그레이션 파일 수정 (#530) feat: 멘토 승격 api 구현 (#532) fix: 대학교 중복 오류 수정 (#510) refactor: 불필요한 로그 삭제 (#543) fix: 운영환경 8081 포트 설정 추가 (#542) fix: dev환경 디비명 변경 (#546) refactor: 불필요한 로그 삭제 (#547) refactor: 학기를 테이블로 관리하도록 변경 (#526) refactor: 모의지원 시 지원한 대학 정보 응답 추가 (#539)
관련 이슈
작업 내용
상황
작업
특이 사항
리뷰 요구사항 (선택)