Skip to content

fix: V010 MySQL 미지원 조건부 DDL 제거로 Flyway 마이그레이션 실패 해결 - #136

Merged
chazy-d merged 2 commits into
developfrom
fix/project-card-profile-image
Aug 6, 2026
Merged

fix: V010 MySQL 미지원 조건부 DDL 제거로 Flyway 마이그레이션 실패 해결#136
chazy-d merged 2 commits into
developfrom
fix/project-card-profile-image

Conversation

@chazy-d

@chazy-d chazy-d commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🔗 관련 이슈 (Related Issue)

📝 작업 내용

운영 배포 중 Flyway validate 실패로 애플리케이션이 부팅되지 않아 배포와 롤백이 모두 실패한 문제를 해결합니다.

원인

V010이 MySQL에서 지원하지 않는 조건부 DDL을 사용했습니다. DROP COLUMN IF EXISTS, CREATE INDEX IF NOT EXISTS, DROP INDEX IF EXISTS는 모두 MariaDB 전용 확장이며 MySQL에는 존재하지 않습니다.

MySQL은 DDL에 트랜잭션이 없어 마이그레이션이 중간에 실패하면 flyway_schema_history에 실패 이력만 남습니다. 이 이력이 있는 한 validate-on-migrate: true 설정에서는 어떤 이미지를 올려도 부팅이 차단되므로, 이전 이미지로의 롤백까지 함께 실패했습니다.

변경 사항

  • V010: ALTER TABLE project_member DROP COLUMN IF EXISTS last_activity_read_at 제거
    • 해당 컬럼은 ProjectMember 엔티티와 운영 DB 어디에도 존재하지 않아 애초에 불필요한 문장이었습니다.
    • 결과적으로 CREATE TABLE project_activity_read 한 문장만 남습니다.
  • V011: 삭제
    • 생성 대상인 idx_activity_log_project_created_id는 운영 DB에 이미 존재합니다.
    • 또한 이 인덱스가 FK273xmgexdxj7yu432gth17luq (project_id → project.id)를 떠받치는 유일한 인덱스라 제거할 수 없습니다(ERROR 1553). MySQL에는 조건부 인덱스 생성 문법이 없으므로 마이그레이션 대상에서 제외했습니다.

선행된 운영 DB 조치 (머지 전 수동 수행 완료)

DROP TABLE project_activity_read;                          -- 수동 생성분 제거 (데이터 0건)
DELETE FROM flyway_schema_history WHERE version = '010';   -- 실패 이력 제거

현재 flyway_schema_history8(BASELINE), 009 두 행만 남아 있으며 둘 다 success = 1입니다. 머지 후 Flyway는 V010 하나만 실행합니다.

토큰이 부족해서 코파일럿을 이용했더니.. sql문 생성시 mariadb 문법을 섞어버렸네요.. ㅠ

✅ PR 체크리스트

  • PR 제목은 커밋 컨벤션을 따랐습니다.
  • 관련 이슈를 연결했습니다.
  • 변경 사항에 대한 테스트를 진행했습니다.

Summary by CodeRabbit

  • 변경 사항
    • 프로젝트 활동 읽음 상태와 관련된 불필요한 데이터베이스 변경 작업을 제거했습니다.
    • 기존 활동 로그 인덱스를 유지하여 데이터베이스 마이그레이션의 안정성을 높였습니다.

chazy-d and others added 2 commits August 6, 2026 16:00
인덱스 생성 시 MySQL 문법 호환성 문제로 인해 V010을 단순화했습니다.
- V010: 컬럼 제거 및 테이블 생성만 수행
- V011: 조회 성능 최적화용 인덱스 생성 (별도 마이그레이션으로 분리)

이미 인덱스가 존재하는 경우 MySQL 8.0과의 호환성을 고려하여
V011에서는 CREATE INDEX만 수행하며, 중복 생성 시에는
운영팀 수동 개입이 필요합니다.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
MySQL 은 DROP COLUMN IF EXISTS / CREATE INDEX IF NOT EXISTS 를 지원하지 않는다
(MariaDB 전용 확장). 이 구문 때문에 V010 이 운영 DB 에서 실패했고,
flyway_schema_history 에 남은 실패 이력이 validate 단계에서 애플리케이션 부팅을
차단해 배포와 롤백이 모두 실패했다.

- V010: DROP COLUMN 문 제거. last_activity_read_at 은 ProjectMember 엔티티와
  운영 DB 어디에도 없어 애초에 불필요했다.
- V011: 삭제. 대상 인덱스는 운영 DB 에 이미 존재하고 FK(project_id -> project.id)
  를 떠받치고 있어 제거할 수 없으므로 마이그레이션 대상에서 제외한다.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chazy-d chazy-d self-assigned this Aug 6, 2026
@chazy-d chazy-d added the fix 버그 수정 label Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

V010 마이그레이션에서 project_member.last_activity_read_at 삭제와 activity_log 인덱스 재생성 DDL을 제거했다. 기존 인덱스가 운영 데이터베이스에 존재하며 외래 키에 필요하다는 설명을 추가했다.

Changes

V010 마이그레이션 DDL 정리

Layer / File(s) Summary
중복 DDL 제거
src/main/resources/db/migration/V010__project_activity_read.sql
조건부 DDL 비호환성 설명을 추가했다. 기존 컬럼 삭제와 activity_log 인덱스 재생성 구문을 제거했다.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 제목이 MySQL 미지원 조건부 DDL 제거와 Flyway 마이그레이션 실패 해결이라는 주요 변경 사항을 명확하게 요약합니다.
Description check ✅ Passed 작업 내용, 원인, 변경 사항, 운영 조치와 체크리스트를 포함해 설명이 대부분 완전합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/resources/db/migration/V010__project_activity_read.sql`:
- Around line 17-19: Update the V010 migration to create the equivalent
composite index on activity_log(project_id, created_at, id), rather than
omitting it based on the operational database assumption. Keep the index aligned
with ActivityLogRepository.findRecentActivitiesByCursor() filtering and ordering
so new databases receive the required index.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a23fba8-1553-4d1e-80c2-e7b2ca8bf33f

📥 Commits

Reviewing files that changed from the base of the PR and between c3211d4 and f1e99f0.

📒 Files selected for processing (1)
  • src/main/resources/db/migration/V010__project_activity_read.sql

Comment on lines +17 to +19

-- activity_log (project_id, created_at, id) 인덱스는 운영 DB에 이미 존재하며
-- FK(project_id -> project.id) 를 떠받치고 있어 제거할 수 없으므로 마이그레이션에 포함하지 않는다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C 6 \
  'activity_log|project_id|created_at|CREATE[[:space:]]+INDEX|FOREIGN KEY' \
  --glob '*.sql' .

Repository: SLAT-TO/SLATE-TO-BE

Length of output: 11690


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf 'SQL migration files:\n'
git ls-files 'src/main/resources/db/migration/*.sql' | sort

printf '\nactivity_log references and DDL patterns:\n'
rg -n -C 8 \
  'CREATE\s+TABLE\s+(?i:activity_log)|activity_log|INDEX|KEY|\bFOREIGN\s+KEY\b|REFERENCES\s+\(?\s*id' \
  --glob '*.sql' src/main/resources/db/migration

printf '\nEntity/controller usage of activity_log indexes/created_at/project_id:\n'
rg -n -C 4 \
  'activityLog|ActivityLog|createdAt|created_at|project_id|projectId' \
  src/main/java || true

Repository: SLAT-TO/SLATE-TO-BE

Length of output: 50376


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf 'activity_log file candidates:\n'
fd -a 'activity_log|ActivityLog|notification' src/main/resources src/main/java | sed 's#^\./##' | head -200

printf '\nMigrations mentioning activity_log explicitly:\n'
for f in $(git ls-files 'src/main/resources/db/migration/*.sql'); do
  if grep -qi 'activity_log' "$f"; then
    echo "--- $f"
    cat -n "$f"
  fi
done

printf '\nRepository/projection files related to ActivityLog:\n'
fd -a 'ActivityLog|activity' src/main/java | sed 's#^\./##' | while read -r f; do
  if grep -qiE 'activity_log|ActivityLog|last_activity_at|lastActivityAt|findLatest|created_at|created' "$f"; then
    echo "--- $f"
    sed -n '1,220p' "$f"
  fi
done

Repository: SLAT-TO/SLATE-TO-BE

Length of output: 15866


activity_log의 최신 조회용 복합 인덱스를 마이그레이션에 포함하세요.

V004/V007activity_log를 삭제하거나 변경하지 않으며, V009V010(project_id, created_at, id) 인덱스 생성을 하지 않습니다. ActivityLogRepository.findRecentActivitiesByCursor()projectId, createdAt, id로 정렬/필터하므로, 운영 DB 의존성 없이 신규 DB에도 동일한 동등 인덱스를 생성하도록 변경하세요.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/resources/db/migration/V010__project_activity_read.sql` around lines
17 - 19, Update the V010 migration to create the equivalent composite index on
activity_log(project_id, created_at, id), rather than omitting it based on the
operational database assumption. Keep the index aligned with
ActivityLogRepository.findRecentActivitiesByCursor() filtering and ordering so
new databases receive the required index.

@chazy-d
chazy-d merged commit 2f1afb5 into develop Aug 6, 2026
2 checks passed
@guingguing
guingguing deleted the fix/project-card-profile-image branch August 11, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix 버그 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant