[Fix] V12 vision_summary_5s 재생성 마이그레이션이 신규 환경에서 실패하지 않도록 수정#66
Merged
Conversation
…otstrap V12 was written to recover from a real prod incident where the table was manually DROPped, so it always ran a plain CREATE TABLE. Any environment that applies V1-V12 from scratch (new staging, MySQL-backed local setup, migration-only DR rebuild) hits "Table already exists" at V12 because V1 already creates the same table and nothing ever dropped it there. Confirmed with mysql:8.0.46 that V12's column/constraint/index list is byte-identical to what V1 + V4 already produce, so V12 now only runs its DDL when vision_summary_5s is actually missing (checked via information_schema + PREPARE/EXECUTE, since MySQL has no IF NOT EXISTS for CREATE INDEX). Verified both the fresh-bootstrap path and the original incident-recovery path (V1-V11, manual DROP, then V12) converge on an identical schema. Since this changes the checksum of a migration already applied in prod, the README's DB 마이그레이션 section now documents that prod needs a `flyway repair` before the next deploy. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughV12 마이그레이션이 기존 ChangesFlyway 마이그레이션 업데이트
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
요약
V12__recreate_vision_summary_5s.sql은 운영 DB에서vision_summary_5s테이블이 실수로 DROP된 사고를 복구하기 위해 작성된 마이그레이션으로, 조건 없이CREATE TABLE을 실행한다.V1부터 전체 이력을 처음부터 적용하는 환경(신규 스테이징, MySQL 기반 로컬 셋업, 마이그레이션만으로 하는 DR 복구 등)에서는V1이 이미 이 테이블을 만들어두는데 그 환경에서는 아무도 지운 적이 없어서, V12에서ERROR 1050 (42S01): Table 'vision_summary_5s' already exists로 실패한다.mysql:8.0.46컨테이너로 확인한 결과 V12의 컬럼/제약조건/인덱스 목록이V1+V4가 이미 만들어내는 스키마와 완전히 동일함을 확인했다. 그래서 V12가vision_summary_5s가 실제로 없을 때만 DDL을 실행하도록 가드를 추가했다(information_schema로 존재 여부 확인 +PREPARE/EXECUTE로 조건부 실행 — MySQL은CREATE INDEX에IF NOT EXISTS를 지원하지 않아CREATE TABLE IF NOT EXISTS만으로는 부족함).이 변경은 운영에 이미 적용된 마이그레이션의 파일 내용을 바꾸기 때문에 Flyway checksum도 함께 바뀐다. 배포 전에 운영 DB에
flyway repair(또는flyway_schema_history의version = 12행 checksum 수동 갱신)를 먼저 실행해야 한다 — 안 하면 다음 앱 기동 시 Flyway checksum 검증에서 실패해 앱이 뜨지 않는다. README의DB 마이그레이션섹션과 마이그레이션 파일 헤더에 이 내용을 문서화해뒀다.이 PR과 관련된 운영 repair는 이미 완료됨 — 운영 DB의 V12 checksum을
67901973→1057297317로 직접 갱신하고 확인까지 마쳤다.테스트
V1~V12를 빈mysql:8.0.46컨테이너에 순서대로 적용 →ERROR 1050 (42S01) at line 12: Table 'vision_summary_5s' already exists로 실패 확인.V1+V4가 만드는 최종 스키마가 V12의CREATE TABLE정의와 컬럼/제약조건/인덱스까지 동일함을SHOW CREATE TABLE로 대조 확인.V12를 포함해V1→V13을 빈 DB에 적용 → 성공, 가드가 스킵되고 스키마 그대로 유지.V1~V11적용 후 수동으로DROP TABLE vision_summary_5s실행, 이후 수정된V12적용 → 테이블 정상 재생성.SHOW CREATE TABLE)를 diff → 완전히 동일.V1~V13전체 마이그레이션을 처음부터 실행 → 성공, checksum 값 확인../gradlew test→BUILD SUCCESSFUL.🤖 Generated with Claude Code