-
Notifications
You must be signed in to change notification settings - Fork 0
[fix] Flyway V9 마이그레이션 실패로 인한 502 에러 수정 #108
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/main/java/com/daramg/server/common/config/FlywayConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.daramg.server.common.config; | ||
|
|
||
| import org.flywaydb.core.Flyway; | ||
| import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class FlywayConfig { | ||
|
|
||
| @Bean | ||
| public FlywayMigrationStrategy flywayMigrationStrategy() { | ||
| return flyway -> { | ||
| flyway.repair(); | ||
| flyway.migrate(); | ||
| }; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| ALTER TABLE users ADD COLUMN role VARCHAR(20) NOT NULL DEFAULT 'USER'; | ||
| ALTER TABLE users ADD COLUMN IF NOT EXISTS role VARCHAR(20) NOT NULL DEFAULT 'USER'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.repair()를 실행하는 것은 위험할 수 있습니다.repair()는 다음과 같은 동작을 수행하는데, 이는 의도치 않은 부작용을 일으킬 수 있습니다.실패한 마이그레이션 기록 삭제: 마이그레이션이 중간에 실패한 경우,
repair는 실패 기록만 제거합니다. 이 상태에서 다시migrate를 실행하면, 멱등성이 보장되지 않은 스크립트는 다시 실패하거나 데이터를 손상시킬 수 있습니다. 모든 마이그레이션을 멱등성 있게 작성하도록 강제하는 것은 좋지만, 실수를 방지하는 안전장치가 사라지는 셈입니다.체크섬 불일치 자동 해결: 이미 적용된 마이그레이션 파일의 내용이 변경되면 체크섬 오류가 발생합니다.
repair는 이를 현재 파일 기준으로 강제 업데이트하는데, 이는 배포된 DB 스키마와 Flyway가 관리하는 버전 간의 불일치를 유발할 수 있습니다. 이는 매우 위험하며, 어떤 변경이 적용되었는지 추적하기 어렵게 만듭니다.Flyway의 마이그레이션 실패는 중요한 이벤트이며, 개발자가 직접 원인을 파악하고 수동으로
repair나 다른 조치를 취하는 것이 안전합니다. 이번 문제의 경우V9스크립트를 멱등적으로 수정한 것으로 충분하며, 이 자동 복구 로직은 제거하는 것을 강력히 권장합니다.