fix: db 마이그레이션 문제 해결 - #133
Conversation
PREPARE/EXECUTE 문법은 MySQL 대화형 CLI에서는 작동하지만, Flyway에서는 Statement 컨텍스트 유지 실패로 인해 검증 오류 발생. CREATE INDEX IF NOT EXISTS로 대체하여 Flyway 호환성 개선. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📝 WalkthroughWalkthrough활동 로그 인덱스의 존재 여부 조회와 동적 SQL 처리를 제거했습니다. Changes활동 로그 인덱스 마이그레이션
Estimated code review effort: 2 (Simple) | ~5 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
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.
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 7-9: Update the V010 project activity index migration to use MySQL
8.0-compatible syntax by removing CREATE INDEX IF NOT EXISTS. Preserve
idempotent behavior for existing or partially applied schemas by moving
index-existence checking into a Java-based Flyway migration using
information_schema.statistics, or by separating database-specific migrations;
add migration integration coverage against the supported production MySQL
version.
🪄 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: 73127d08-d690-49e1-9147-2fcf3c47657e
📒 Files selected for processing (1)
src/main/resources/db/migration/V010__project_activity_read.sql
| -- Flyway 호환성: PREPARE/EXECUTE 대신 직접 조건부 생성 | ||
| CREATE INDEX IF NOT EXISTS idx_activity_log_project_created_id | ||
| ON activity_log (project_id, created_at, id); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Repository files matching relevant names:\n'
git ls-files | rg '(^|/)(V010__project_activity_read\.sql|.*[Pp]roject[Aa]ctivityRead[Cc]ommand[Rr]epository.*|.*flyway.*|.*db/.*|.*application.*|.*README.*|.*build.gradle.*|.*pom.xml.*|.*gradle.properties.*|.*settings.gradle.*|.*docker-compose.*|.*Dockerfile.*)' || true
printf '\nFile: V010__project_activity_read.sql\n'
sed -n '1,80p' src/main/resources/db/migration/V010__project_activity_read.sql 2>/dev/null || true
printf '\nRepository occurrences of create_index_if_not_exists or ProjectActivityReadCommandRepository:\n'
rg -n "create_index_if_not_exists|CREATE INDEX IF NOT EXISTS|ProjectActivityReadCommandRepository|MYSQL_|jdbc:|flyway|Flyway|DatabaseType|dbType|schema:|mysql" -S . || true
printf '\nJava/resource outline for candidate repository files using Python (text scan):\n'
python3 - <<'PY'
from pathlib import Path
matches = []
for p in Path('.').rglob('*'):
if p.is_file() and p.suffix in {'.java','.kt','.ts','.js','.yaml','.yml','.sql','.gradle','.properties','.xml'}:
s=p.read_text(errors='ignore')[:20000]
if any(x in s for x in ['ProjectActivityReadCommandRepository','MYSQL_','`@Sql`','CREATE INDEX IF NOT EXISTS','flyway','jdbc:']):
matches.append(str(p))
for m in matches[:50]:
print(m)
PYRepository: SLAT-TO/SLATE-TO-BE
Length of output: 5825
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Check Maven Flyway dependency/plugin and possible Flyway versions from common config files:\n'
for f in pom.xml build.gradle settings.gradle gradle.properties; do
if [ -f "$f" ]; then
echo "--- $f ---"
rg -n "flyway|flyway-core|org.flywaydb|version" "$f" || true
fi
done
printf '\nAll SQL migration files mentioning conditional index/statistics:\n'
rg -n "information_schema\.statistics|CREATE INDEX IF NOT EXISTS|CREATE UNIQUE INDEX IF NOT EXISTS|REPLACE INTO|INSERT IGNORE|CONCAT\(" src/main/resources/db/migration src/main/resources 2>/dev/null || true
printf '\nRead migration files that mention activity_log or index conditional patterns:\n'
for f in $(rg -l "activity_log|CREATE INDEX IF NOT EXISTS|information_schema\.statistics" src/main/resources/db/migration src/main/resources 2>/dev/null); do
echo "--- $f ---"
sed -n '1,140p' "$f"
doneRepository: SLAT-TO/SLATE-TO-BE
Length of output: 4461
🌐 Web query:
MySQL 8.0 CREATE INDEX IF NOT EXISTS syntax documentation
💡 Result:
MySQL 8.0 does not support the CREATE INDEX IF NOT EXISTS syntax [1][2]. As of August 2026, the CREATE INDEX statement in MySQL 8.0 does not include an IF NOT EXISTS clause [3][4]. This limitation has been formally recognized as a feature request [1]. To achieve conditional index creation in MySQL 8.0, developers typically use procedural code (such as a stored procedure) or dynamic SQL to check for the index's existence in the INFORMATION_SCHEMA.STATISTICS table before executing the CREATE INDEX or ALTER TABLE statement [5][6]. Example approach using dynamic SQL: SET @dbname = DATABASE; SET @tablename = 'your_table_name'; SET @indexname = 'your_index_name'; SET @sql = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND INDEX_NAME = @indexname) > 0, 'SELECT "Index already exists" AS note', CONCAT('CREATE INDEX ', @indexname, ' ON ', @tablename, ' (column_name)'))); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
Citations:
- 1: https://bugs.mysql.com/bug.php?id=106000
- 2: MySQL doesn't support
CREATE INDEX IF NOT EXISTSPrivateBin/PrivateBin#943 - 3: https://dev.mysql.com/doc/refman/8.0/en/create-index.html
- 4: https://docs.oracle.com/cd/E17952_01/mysql-8.0-en/create-index.html
- 5: https://dba.stackexchange.com/questions/24531/mysql-create-index-if-not-exists
- 6: https://stackoverflow.com/questions/30259196/add-index-to-table-if-it-does-not-exist
MySQL 호환 구문으로 변경해야 합니다.
운영 DB 설정은 MySQL 8.0을 사용하며, CREATE INDEX IF NOT EXISTS는 MySQL 8.0에서 지원되지 않습니다. MySQL 환경에서 V010__project_activity_read.sql은 Line 8에서 실패합니다.
MySQL용 SQL에서 IF NOT EXISTS를 제거하세요. 기존 스키마와 부분 적용 복구를 지원하려면 information_schema.statistics 확인을 Java 기반 Flyway migration으로 전환하거나 DB별 migration을 분리하세요. 실제 운영 DB 엔진과 버전에서 migration 통합 테스트를 추가하세요.
🤖 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
7 - 9, Update the V010 project activity index migration to use MySQL
8.0-compatible syntax by removing CREATE INDEX IF NOT EXISTS. Preserve
idempotent behavior for existing or partially applied schemas by moving
index-existence checking into a Java-based Flyway migration using
information_schema.statistics, or by separating database-specific migrations;
add migration integration coverage against the supported production MySQL
version.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b410741 to
4e09a4c
Compare
🔗 관련 이슈 (Related Issue)
📝 작업 내용
V010__project_activity_read.sql이 MySQL 에서 실행되지 않아 Flyway 마이그레이션이 실패하던 문제를 해결했습니다.information_schema에서 조회한 뒤PREPARE/EXECUTE로 동적 실행하던 블록을 제거했습니다.DROP INDEX IF EXISTS후CREATE INDEX하는 형태로 단순화했습니다.✅ PR 체크리스트
Summary by CodeRabbit