Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.PrePersist;
import java.time.ZonedDateTime;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand All @@ -34,9 +33,6 @@ public class Mentoring extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private ZonedDateTime createdAt;

@Column
private ZonedDateTime confirmedAt;

Expand All @@ -62,11 +58,6 @@ public Mentoring(long mentorId, long menteeId, VerifyStatus verifyStatus) {
this.verifyStatus = verifyStatus;
}

@PrePersist
public void onPrePersist() {
this.createdAt = ZonedDateTime.now(UTC).truncatedTo(MICROS); // 나노초 6자리 까지만 저장
}

public void confirm(VerifyStatus status) {
this.verifyStatus = status;
this.confirmedAt = ZonedDateTime.now(UTC).truncatedTo(MICROS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ ALTER TABLE application
ADD COLUMN created_at DATETIME(6),
ADD COLUMN updated_at DATETIME(6);

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);

Comment on lines -5 to -12
Copy link
Contributor

Choose a reason for hiding this comment

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

@coderabbitai
이미 개발서버에 반영된 flaway 스크립트 파일 수정해도 문제 없는지 알려줘

Copy link

Choose a reason for hiding this comment

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

@Gyuhyeok99

Flyway 마이그레이션 파일 수정 관련 답변

이미 개발 서버에 반영된 Flyway 스크립트를 수정하는 것은 일반적으로 권장되지 않습니다. 다음 이유들 때문입니다:

1. 체크섬 검증 실패 위험

Flyway는 각 마이그레이션 파일의 체크섬을 flyway_schema_history 테이블에 저장합니다. 이미 실행된 파일을 수정하면 체크섬이 달라져서 다음 배포 시 Flyway가 검증 오류를 발생시킵니다:

Validate failed: Migration checksum mismatch

2. 환경 간 불일치 문제

  • 다른 개발자의 로컬 환경
  • 스테이징 환경
  • 프로덕션 환경

위 환경들과 동기화 문제가 발생할 수 있습니다.

3. 현재 PR의 접근 방식 분석

PR에서 수행하는 작업:

  1. flyway_schema_history에서 V34 레코드 삭제
  2. application 테이블에서 컬럼 수동 삭제
  3. ✅ 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의 의도된 사용 방식입니다.

어떤 방식을 선택하시겠습니까?

Copy link
Contributor

Choose a reason for hiding this comment

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

@whqtker 이거 확인 한 번 부탁드립니다

Copy link

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!

Copy link
Member Author

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는 적용되지 않는 거 아니니 ?

Copy link

Choose a reason for hiding this comment

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

@whqtker 정확한 지적입니다! 말씀하신 대로 V34가 실행 중 실패했기 때문에 V35로 해결할 수 없는 상황입니다.

상황 분석

문제점

  1. V34 스크립트가 존재하지 않는 gpa 테이블에 대한 ALTER TABLE 구문을 포함
  2. Flyway가 V34 실행 중 gpa 테이블에서 에러 발생
  3. V34가 실패 상태로 flyway_schema_history에 기록됨 (또는 부분적으로만 실행됨)
  4. 이후 마이그레이션(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에서 수행 중)

  1. flyway_schema_history에서 V34 레코드 삭제
  2. application 테이블의 created_at, updated_at 수동 삭제
  3. ✅ V34 파일 수정 (gpa, language_test 제거)
  4. ✅ Flyway 재실행

결론

이전 답변에서 V35 생성을 권장했지만, V34가 실패한 상황에서는 V34 자체를 수정하는 것이 올바른 접근입니다. 제 답변이 현재 상황을 충분히 고려하지 못했습니다.

현재 PR의 접근 방식이 정확하며, 다음을 확인하시면 됩니다:

  • 개발 서버에서 V34 관련 히스토리 삭제
  • application 테이블 컬럼 수동 삭제
  • 수정된 V34로 재실행
  • 팀원들에게 동일한 작업 공유

Copy link
Member Author

@whqtker whqtker Oct 14, 2025

Choose a reason for hiding this comment

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

@coderabbitai 답변, PR 등을 고려하지 않고 오로지 현 문제에 초점을 맞췄을 때, 가장 현명한 해결 방법은 무엇인가 ?

Copy link

Choose a reason for hiding this comment

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

@whqtker

가장 현명한 해결 방법

오로지 기술적 관점에서 볼 때, 가장 깔끔한 해결 방법은 다음과 같습니다:

해결 전략: 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 migrate

6️⃣ 검증

-- 모든 테이블에 컬럼이 올바르게 추가되었는지 확인
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;

왜 이 방법이 가장 현명한가?

장점

  1. 마이그레이션 히스토리가 깔끔함 - V34가 실제 의도대로 기록됨
  2. 재현 가능성 - 새로운 환경(로컬, CI/CD)에서 동일하게 작동
  3. Flyway 원칙 준수 - repair 명령어는 이런 상황을 위해 존재함
  4. 향후 문제 방지 - 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 수정이 최선입니다.

ALTER TABLE post_image
ADD COLUMN created_at DATETIME(6),
ADD COLUMN updated_at DATETIME(6);
Expand All @@ -35,7 +27,6 @@ ALTER TABLE mentor
ADD COLUMN updated_at DATETIME(6);

ALTER TABLE mentoring
ADD COLUMN created_at DATETIME(6),
ADD COLUMN updated_at DATETIME(6);

ALTER TABLE liked_news
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public MentoringFixtureBuilder mentoring() {
return new MentoringFixtureBuilder(mentoringRepository);
}

public MentoringFixtureBuilder createdAt(ZonedDateTime createdAt) {
this.createdAt = createdAt;
return this;
}

public MentoringFixtureBuilder confirmedAt(ZonedDateTime confirmedAt) {
this.confirmedAt = confirmedAt;
return this;
Expand Down Expand Up @@ -63,7 +58,6 @@ public MentoringFixtureBuilder menteeId(long menteeId) {
public Mentoring create() {
Mentoring mentoring = new Mentoring(
null,
createdAt,
confirmedAt,
checkedAtByMentor,
checkedAtByMentee,
Expand Down
Loading