fix: 유니크 제약조건 제거 전 인덱스 추가 - #357
Conversation
📝 WalkthroughWalkthrough데이터베이스 마이그레이션 파일 V49에서 users 테이블의 기존 복합 유니크 제약 조건(uq_users_university_id_student_number_active)을 제거하고, 새로운 인덱스(idx_users_university_id)를 university_id 컬럼에 추가하는 ALTER TABLE 문이 단일 명령어로 구현되었습니다. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/main/resources/db/migration/V49__remove_unique_constraint_on_user_student_number.sql`:
- Line 3: This migration drops the unique index
uq_users_university_id_student_number_active; if this V49 migration has already
been applied in any environment do NOT modify this file (it will break Flyway
checksums) — instead create a new migration (e.g., V50__) that performs DROP
INDEX; if it has not been deployed, ensure you prepare a rollback/data-cleanup
plan: scan for and remove/merge duplicate rows on
users.student_number/university_id before running DROP INDEX, and document the
steps so the migration can be reapplied safely.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 19baf85d-ea41-440a-8653-80eed7356918
📒 Files selected for processing (1)
src/main/resources/db/migration/V49__remove_unique_constraint_on_user_student_number.sql
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
src/main/resources/db/migration/**/*.sql
⚙️ CodeRabbit configuration file
src/main/resources/db/migration/**/*.sql: Flyway 마이그레이션 리뷰 규칙:
- 버전 파일명 규칙(V{number}__{description}.sql) 위반 여부를 우선 확인한다.
- 이미 배포된 마이그레이션 수정/재번호 부여 위험이 있으면 반드시 차단 코멘트를 남긴다.
- 파괴적 변경(drop, rename 등)은 롤백 가능성과 운영 영향 관점에서 검토한다.
Files:
src/main/resources/db/migration/V49__remove_unique_constraint_on_user_student_number.sql
**/*
⚙️ CodeRabbit configuration file
**/*: 공통 리뷰 톤 가이드:
- 모든 코멘트는 첫 줄에
[LEVEL: ...]태그를 포함한다.- 과장된 표현 없이 사실 기반으로 작성한다.
- 한 코멘트에는 하나의 이슈만 다룬다.
- 코드 예시가 필요하면 최소 수정 예시를 제시한다.
- 가독성/단순화/확장성 이슈를 발견하면 우선순위를 높여 코멘트한다.
Files:
src/main/resources/db/migration/V49__remove_unique_constraint_on_user_student_number.sql
🔇 Additional comments (1)
src/main/resources/db/migration/V49__remove_unique_constraint_on_user_student_number.sql (1)
1-3: [LEVEL: 승인]단일 ALTER TABLE 문으로 인덱스 추가 후 유니크 제약조건 제거 - 올바른 접근입니다.
FK(Foreign Key)가 참조하는 컬럼에는 반드시 인덱스가 존재해야 합니다. 기존 유니크 인덱스(
uq_users_university_id_student_number_active)가university_id를 첫 번째 컬럼으로 포함하여 FK 인덱스 역할을 했으므로, 대체 인덱스(idx_users_university_id)를 먼저 추가한 후 유니크 인덱스를 삭제하는 것이 정확합니다.단일
ALTER TABLE문 내에서 두 작업을 수행하면 MySQL이 이를 원자적으로 처리하여 FK 참조가 끊기는 순간이 발생하지 않습니다.
🔍 개요
users테이블에FOREIGN KEY (university_id) REFERENCES university (id)외래 키 존재외래 키 제약 조건은
university_id컬럼에 대한 인덱스를 필요로 함제거한 제약조건의 유니크 인덱스의 첫 번째 컬럼이
university_id라서 외래 키가 이 인덱스를 사용인덱스 삭제 시도 → 외래 키가 인덱스 필요 → 삭제 불가
🚀 주요 변경 내용
university_id컬럼에 대한 인덱스를 추가합니다.💬 참고 사항
✅ Checklist (완료 조건)