Skip to content

fix: db 마이그레이션 문제 해결 - #133

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

fix: db 마이그레이션 문제 해결#133
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)

  • 없음

📝 작업 내용

V010__project_activity_read.sql 이 MySQL 에서 실행되지 않아 Flyway 마이그레이션이 실패하던 문제를 해결했습니다.

  • 인덱스 존재 여부를 information_schema 에서 조회한 뒤 PREPARE / EXECUTE 로 동적 실행하던 블록을 제거했습니다.
  • DROP INDEX IF EXISTSCREATE INDEX 하는 형태로 단순화했습니다.
  • 사용하지 않는 Maven Wrapper 파일을 삭제했습니다.

✅ PR 체크리스트

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

Summary by CodeRabbit

  • 성능 개선
    • 프로젝트 활동 기록 조회에 사용되는 인덱스 설정을 개선해 관련 조회 성능과 안정성을 높였습니다.
    • 이미 인덱스가 존재하는 환경에서도 데이터베이스 변경 작업이 안전하게 처리됩니다.

PREPARE/EXECUTE 문법은 MySQL 대화형 CLI에서는 작동하지만,
Flyway에서는 Statement 컨텍스트 유지 실패로 인해 검증 오류 발생.
CREATE INDEX IF NOT EXISTS로 대체하여 Flyway 호환성 개선.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

활동 로그 인덱스의 존재 여부 조회와 동적 SQL 처리를 제거했습니다. CREATE INDEX IF NOT EXISTS를 사용해 동일한 인덱스를 조건부로 생성하도록 마이그레이션을 단순화했습니다.

Changes

활동 로그 인덱스 마이그레이션

Layer / File(s) Summary
인덱스 조건부 생성 변경
src/main/resources/db/migration/V010__project_activity_read.sql
information_schema 조회와 PREPARE/EXECUTE 처리를 제거했습니다. idx_activity_log_project_created_idproject_id, created_at, id 컬럼으로 조건부 생성합니다.

Estimated code review effort: 2 (Simple) | ~5 minutes

Possibly related PRs

  • SLAT-TO/SLATE-TO-BE#125: 동일한 마이그레이션 파일과 활동 로그 인덱스를 수정했으며, 동적 조건부 생성 로직과 직접 연결됩니다.

Suggested labels: fix

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning 변경 사항은 인덱스 생성 마이그레이션 수정이며, 연결된 이슈 #1의 공통 응답·예외 처리 구조 목표를 충족하지 않습니다. 관련 이슈를 마이그레이션 문제에 해당하는 이슈로 수정하거나, 이슈 #1의 요구 사항을 구현하세요.
Out of Scope Changes check ⚠️ Warning SQL 마이그레이션 변경은 연결된 이슈 #1의 공통 백엔드 구조 추가 범위와 무관합니다. 마이그레이션 변경을 적절한 이슈로 연결하거나, 이 PR을 연결된 이슈 #1의 범위에 맞게 분리하세요.
Description check ⚠️ Warning 작업 내용은 구체적이지만 관련 이슈, PR 체크리스트, 테스트 수행 여부가 누락되었습니다. 관련 이슈 섹션과 PR 체크리스트를 추가하고, 변경 사항에 대한 테스트 수행 결과를 명시하세요.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ 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.

❤️ 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 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3bfd5ba and b410741.

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

Comment on lines +7 to +9
-- Flyway 호환성: PREPARE/EXECUTE 대신 직접 조건부 생성
CREATE INDEX IF NOT EXISTS idx_activity_log_project_created_id
ON activity_log (project_id, created_at, 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.

🎯 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)
PY

Repository: 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"
done

Repository: 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:


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>
@chazy-d
chazy-d force-pushed the fix/project-card-profile-image branch from b410741 to 4e09a4c Compare August 6, 2026 06:11
@chazy-d chazy-d self-assigned this Aug 6, 2026
@chazy-d
chazy-d merged commit c3211d4 into develop Aug 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant