Skip to content

fix: 유니크 제약조건 제거 전 인덱스 추가 - #357

Merged
dh2906 merged 1 commit into
developfrom
fix/solve-v49-migration
Mar 8, 2026
Merged

fix: 유니크 제약조건 제거 전 인덱스 추가#357
dh2906 merged 1 commit into
developfrom
fix/solve-v49-migration

Conversation

@dh2906

@dh2906 dh2906 commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

🔍 개요

  • users 테이블에 FOREIGN KEY (university_id) REFERENCES university (id) 외래 키 존재

  • 외래 키 제약 조건은 university_id 컬럼에 대한 인덱스를 필요로 함

  • 제거한 제약조건의 유니크 인덱스의 첫 번째 컬럼이 university_id라서 외래 키가 이 인덱스를 사용

  • 인덱스 삭제 시도 → 외래 키가 인덱스 필요 → 삭제 불가

  • close #이슈번호

🚀 주요 변경 내용

  • 유니크 제약조건 삭제 전 university_id 컬럼에 대한 인덱스를 추가합니다.

💬 참고 사항


✅ Checklist (완료 조건)

  • 코드 스타일 가이드 준수
  • 테스트 코드 포함됨
  • Reviewers / Assignees / Labels 지정 완료
  • 보안 및 민감 정보 검증 (API 키, 환경 변수, 개인정보 등)

@dh2906 dh2906 self-assigned this Mar 8, 2026
@dh2906 dh2906 added the DB DB 마이그레이션을 위한 라벨입니다. label Mar 8, 2026
@coderabbitai

coderabbitai Bot commented Mar 8, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

데이터베이스 마이그레이션 파일 V49에서 users 테이블의 기존 복합 유니크 제약 조건(uq_users_university_id_student_number_active)을 제거하고, 새로운 인덱스(idx_users_university_id)를 university_id 컬럼에 추가하는 ALTER TABLE 문이 단일 명령어로 구현되었습니다.

Changes

Cohort / File(s) Summary
Database Schema Migration
src/main/resources/db/migration/V49__remove_unique_constraint_on_user_student_number.sql
기존의 복합 유니크 인덱스 uq_users_university_id_student_number_active를 제거하고 university_id에 새로운 인덱스 idx_users_university_id를 추가합니다.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • fix: 학번 유니크 제약조건 제거 #356: 동일한 마이그레이션 파일 V49__remove_unique_constraint_on_user_student_number.sql을 수정하여 uq_users_university_id_student_number_active 제약 조건을 제거하고 인덱스를 추가하는 작업과 관련이 있습니다.

Poem

🐰 유니크 제약을 제거하고,
새로운 인덱스를 심어 놓네요,
스키마의 정원을 가꾸는 마이그레이션,
데이터베이스의 성능 향상을 위해 🌱

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 제목이 pull request의 주요 변경 사항(유니크 제약조건 제거 전 인덱스 추가)을 명확하게 요약하고 있습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed 풀 리퀘스트 설명은 변경사항과 관련이 있으며, 외래 키와 인덱스 문제를 명확히 설명합니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/solve-v49-migration

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 and usage tips.

@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 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6308ce6 and 3ec159e.

📒 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 참조가 끊기는 순간이 발생하지 않습니다.

@dh2906
dh2906 merged commit cbcbeb6 into develop Mar 8, 2026
2 checks passed
@dh2906
dh2906 deleted the fix/solve-v49-migration branch March 8, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DB DB 마이그레이션을 위한 라벨입니다.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant