Skip to content

Comments

feat: DB 마이그레이션 및 Flyway 자동화 적용#345

Merged
eunseo9311 merged 7 commits intomainfrom
develop
Feb 14, 2026
Merged

feat: DB 마이그레이션 및 Flyway 자동화 적용#345
eunseo9311 merged 7 commits intomainfrom
develop

Conversation

@eunseo9311
Copy link
Contributor

#️⃣ Issue Number

#344

📝 요약(Summary)

  • Flyway 자동 마이그레이션 설정 추가
  • V2~V4 마이그레이션 스크립트 적용
  • V2: PK/FK 타입 정렬
  • V3: varchar → enum 변환
  • V4: NOT NULL, default, rating 타입 정렬

💬 공유사항 to 리뷰어

Test

  • dev 서버에서 Flyway 마이그레이션 정상 실행 확인 ✅
  • flyway_schema_history 테이블 기록 확인 ✅

✅ PR Checklist

PR이 다음 요구 사항을 충족하는지 확인하세요.

  • 커밋 메시지 컨벤션에 맞게 작성했습니다.
  • 변경 사항에 대한 테스트를 했습니다.(버그 수정/기능에 대한 테스트).

eunseo9311 and others added 7 commits February 4, 2026 14:31
- V1: 베이스라인 스키마 정의
- V2: PK/FK 타입 정렬 (int → bigint)
- V3: varchar → enum 타입 변환
- V4: 제약조건 및 기본값 추가
- 검증 SQL 및 마이그레이션 가이드 문서 추가
V1에 이미 college.name의 UNIQUE 제약조건이 존재하므로
V4에서 중복 추가하는 부분 제거
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
feat: DB 마이그레이션 스크립트 추가
@eunseo9311 eunseo9311 self-assigned this Feb 14, 2026
@eunseo9311 eunseo9311 added the refactoring 리팩토링 label Feb 14, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @eunseo9311, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 데이터베이스 스키마 변경 관리를 자동화하기 위해 Flyway를 도입하고, 기존 스키마의 여러 문제점을 개선하는 데 중점을 둡니다. PK/FK 타입 통일, varcharENUM으로 변환, 그리고 NOT NULLDEFAULT 값과 같은 제약조건을 추가하여 데이터의 일관성과 무결성을 크게 향상시킵니다. 또한, 안전한 마이그레이션 절차를 위한 상세한 가이드와 데이터 검증 도구를 제공하여 잠재적인 문제를 사전에 방지하도록 돕습니다.

Highlights

  • Flyway 자동 마이그레이션 적용: 데이터베이스 스키마 관리를 위해 Flyway를 도입하고, 개발 및 운영 환경에 자동 마이그레이션 설정을 추가했습니다.
  • V2: PK/FK 타입 정렬: 기존 int 타입의 PK/FK 컬럼들을 BIGINT로 통일하여 데이터 일관성을 확보했습니다.
  • V3: varchar → enum 변환: 여러 테이블의 varchar 타입 컬럼들을 ENUM 타입으로 변환하여 데이터 유효성을 강화하고 가독성을 높였습니다. 이 과정에서 데이터 검증 스크립트가 함께 제공됩니다.
  • V4: 제약조건 및 기본값 추가: NOT NULL 제약조건, DEFAULT 값 설정, rating 타입 통일 등 데이터 무결성을 위한 추가적인 스키마 변경을 적용했습니다.
  • 마이그레이션 가이드 및 검증 스크립트 제공: 안전한 마이그레이션 실행을 위한 상세 가이드(MIGRATION_GUIDE.md)와 데이터 검증 스크립트(run_validation.sh, validate_enum_data.sql, validate_simple.sql)를 추가했습니다.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • MIGRATION_GUIDE.md
    • DB 마이그레이션 실행을 위한 상세 가이드 문서가 추가되었습니다.
  • build.gradle
    • Flyway Core 및 Flyway MySQL 의존성이 추가되었습니다.
  • check_fk_constraints.sql
    • FK 제약조건명을 확인하는 SQL 스크립트가 추가되었습니다.
  • run_validation.sh
    • Enum 데이터 변환 전 검증을 위한 쉘 스크립트가 추가되었습니다.
  • src/main/resources/application-dev.yml
    • Flyway 자동 마이그레이션 설정이 추가되었습니다.
    • JWT 토큰 유효 기간이 60초에서 86400초로, 리프레시 토큰 유효 기간이 180초에서 604800초로 연장되었습니다.
  • src/main/resources/application-prod.yml
    • Flyway 자동 마이그레이션 설정이 추가되었습니다.
  • src/main/resources/db/migration/V1__baseline.sql
    • 기존 데이터베이스 스키마를 Flyway의 초기 베이스라인으로 설정하는 SQL 스크립트가 추가되었습니다.
  • src/main/resources/db/migration/V2__align_pk_and_fk_types.sql
    • PK/FK 컬럼의 데이터 타입을 int에서 BIGINT로 통일하는 마이그레이션 스크립트가 추가되었습니다.
  • src/main/resources/db/migration/V3__convert_varchar_to_enum.sql
    • 여러 테이블의 varchar 타입 컬럼을 ENUM 타입으로 변환하는 마이그레이션 스크립트가 추가되었습니다.
  • src/main/resources/db/migration/V4__add_constraints_and_defaults.sql
    • NOT NULL 제약조건, DEFAULT 값, rating 타입 통일 등 추가적인 데이터베이스 제약조건을 적용하는 마이그레이션 스크립트가 추가되었습니다.
  • validate_enum_data.sql
    • Enum 데이터 변환 전 상세한 데이터 불일치 검증을 위한 SQL 스크립트가 추가되었습니다.
  • validate_simple.sql
    • Enum 데이터 변환 전 간단한 데이터 불일치 검증을 위한 SQL 스크립트가 추가되었습니다.
Activity
  • Flyway 자동 마이그레이션 설정이 추가되었습니다.
  • V2~V4 마이그레이션 스크립트가 적용되었습니다.
  • 개발 서버에서 Flyway 마이그레이션이 정상적으로 실행됨을 확인했습니다.
  • flyway_schema_history 테이블에 기록이 정상적으로 남았음을 확인했습니다.
  • 커밋 메시지 컨벤션에 맞춰 작성되었으며, 변경 사항에 대한 테스트를 완료했습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


DB 스키마, Flyway로 정돈하니, 타입 맞추고 Enum 변환, 데이터 무결성, 이제 안심. 코드 리뷰, 모두가 웃음꽃 피네.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@eunseo9311 eunseo9311 merged commit 5c6ee39 into main Feb 14, 2026
2 checks passed
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이 PR은 Flyway를 도입하여 데이터베이스 마이그레이션을 자동화하고, 관련 스크립트와 상세한 가이드를 추가하여 스키마 변경 관리를 체계적으로 개선했습니다. 전반적으로 완성도가 높지만, run_validation.sh 스크립트에서 데이터베이스 비밀번호가 명령줄 인수로 전달되어 시스템의 다른 사용자에게 노출될 수 있는 보안 취약점이 발견되었습니다. 이 외에도 보안 및 코드 명확성 개선을 위한 몇 가지 제안 사항이 있습니다.


# 검증 쿼리 실행
RESULT_FILE="validation_result_${ENV}_$(date +%Y%m%d_%H%M%S).txt"
mysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" < validate_enum_data.sql > "$RESULT_FILE" 2>&1
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The script passes the database password directly to the mysql command using the -p flag. This makes the password visible in the system's process list (e.g., via ps aux) to any other user on the same machine, as the mysql client itself warns: [Warning] Using a password on the command line interface can be insecure. It is recommended to use the MYSQL_PWD environment variable to pass the password, which is a more secure approach to prevent exposure in process lists or shell history.

Suggested change
mysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" < validate_enum_data.sql > "$RESULT_FILE" 2>&1
# Use MYSQL_PWD environment variable to avoid exposing password in process list
export MYSQL_PWD="$DB_PASS"
mysql -h "$DB_HOST" -u "$DB_USER" "$DB_NAME" < validate_enum_data.sql > "$RESULT_FILE" 2>&1
unset MYSQL_PWD

# AWS RDS 스냅샷으로 복원
aws rds restore-db-instance-from-db-snapshot \
--db-instance-identifier your-db-restored \
--db-snapshot-identifier eatssu-dev-pre-migration-20260207
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

롤백 명령어 예시에 포함된 스냅샷 식별자(eatssu-dev-pre-migration-20260207)에 미래 날짜가 사용되었습니다. 이는 예시일 수 있으나, 실제 실행 시 혼동을 주거나 복사-붙여넣기 오류를 유발할 수 있습니다. your-snapshot-identifier와 같이 더 일반적인 플레이스홀더로 변경하는 것을 제안합니다.

Suggested change
--db-snapshot-identifier eatssu-dev-pre-migration-20260207
--db-snapshot-identifier your-snapshot-identifier

-- 1. FK 제약조건 해제
-- 2. PK 타입 변경
-- 3. FK 컬럼 타입 변경
-- 4. FK 제약조건 재생성
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

주석에 "4. FK 제약조건 재생성"이라고 명시되어 있지만, 실제 스크립트는 SET FOREIGN_KEY_CHECKS를 이용해 제약조건 검사를 비활성화했다가 다시 활성화할 뿐, 제약조건을 재생성하지는 않습니다. MySQL에서 호환되는 타입 변경 시 제약조건은 유지되므로 스크립트 동작은 올바릅니다. 다만, 주석을 "4. FK 제약조건 검사 복원" 등으로 수정하여 실제 동작과 일치시키는 것이 좋겠습니다.

-- 4. FK 제약조건 검사 복원

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring 리팩토링

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant