Skip to content

665 db 버전 관리 툴 적용 - #666

Merged
ByunDohwi merged 11 commits into
developfrom
665-db-버전-관리-툴-적용
May 15, 2026

Hidden character warning

The head ref may contain hidden characters: "665-db-\ubc84\uc804-\uad00\ub9ac-\ud234-\uc801\uc6a9"
Merged

ByunDohwi merged 11 commits into
developfrom
665-db-버전-관리-툴-적용

Conversation

@ByunDohwi

@ByunDohwi ByunDohwi commented May 15, 2026 •

Copy link
Copy Markdown
Member

DB 형상관리 툴인 flyway를 적용하였습니다.
파일 형식은
V{생성일의 년월일시분}__{변경 내용}.sql
입니다.
관련된 상세한 사항은 노션 백엔드 Docs에 적어놓았으니 읽어주세요.

Summary by CodeRabbit

릴리스 노트

  • Chores
    • 데이터베이스 마이그레이션 시스템을 초기화했습니다.
    • 데이터베이스 스키마 버전 관리를 설정했습니다.
    • 빌드 구성에서 데이터베이스 마이그레이션 도구를 추가했습니다.

@ByunDohwi ByunDohwi self-assigned this May 15, 2026
@ByunDohwi ByunDohwi added the 프로젝트 세팅 프로젝트 세팅 label May 15, 2026
@ByunDohwi
ByunDohwi requested a review from imhanseong as a code owner May 15, 2026 01:51
@ByunDohwi ByunDohwi linked an issue May 15, 2026 that may be closed by this pull request
@ByunDohwi
ByunDohwi requested a review from 1210thatman as a code owner May 15, 2026 01:51
@coderabbitai

coderabbitai Bot commented May 15, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@ByunDohwi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 41 minutes and 19 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3d9e9287-a8f5-40a8-ab28-395b3051df95

📥 Commits

Reviewing files that changed from the base of the PR and between 544aa83 and 7a7f2f9.

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

Walkthrough

Flyway 데이터베이스 마이그레이션 시스템을 도입하여 빌드 의존성, 애플리케이션 설정, 초기 스키마 정의, 그리고 마이그레이션 정리를 수행합니다. 관리자와 사용자 중심의 도메인 모델을 V1 baseline으로 통합하고 버전 관리를 시작합니다.

Changes

Flyway 마이그레이션 시스템 도입

Layer / File(s) Summary
빌드 및 의존성 설정
.gitignore, buildSrc/src/main/kotlin/Dependencies.kt, build.gradle.kts
Flyway 코어 및 MySQL 드라이버 의존성을 정의하고 빌드에 포함시키며, IntelliJ IDEA 설정 무시 규칙을 .idea/*로 조정하고 환경 변수, 파일 템플릿, AI 관련 규칙을 추가.
마이그레이션 설정
src/main/resources/application.yaml
Flyway 마이그레이션 활성화, baseline 자동 생성(baseline-on-migrate: true), baseline 버전(1), 마이그레이션 위치(classpath:db/migration)를 설정.
초기 데이터베이스 스키마
src/main/resources/db/migration/V1__baseline.sql
관리자(tbl_admin, tbl_admin_device_token), 사용자(tbl_user, tbl_user_device_token), 공지(tbl_notice), 신청(tbl_application, tbl_application_story), 출석(tbl_attendance), 교실(tbl_classroom), 상태(tbl_status), 주말식사(tbl_weekend_meal, tbl_weekend_meal_period), 자기학습(tbl_self_study), 시간표(tbl_timetable), 토픽 구독(tbl_topic_subscription), 아웃박스(tbl_outbox), 스케줄(tbl_schedule) 테이블을 생성하고 외래키(CASCADE/SET NULL), unique 제약, 인덱스를 정의.
마이그레이션 정리
src/main/resources/db/migration/V202605142000__Drop_User.sql
V1 baseline 통합 후 임시 사용자 테이블(user)을 삭제.

Sequence Diagram(s)

sequenceDiagram
  participant SpringBoot as Spring Boot App
  participant Flyway as Flyway Engine
  participant Migration as V1__baseline.sql
  participant Database as MySQL Database

  SpringBoot->>Flyway: 애플리케이션 시작 시 마이그레이션 실행
  Flyway->>Database: baseline 테이블 확인
  Flyway->>Migration: classpath:db/migration 스캔 및 마이그레이션 파일 로드
  Migration->>Database: 테이블 생성 (tbl_admin, tbl_user, tbl_notice 등)
  Migration->>Database: 외래키 및 제약조건 설정
  Migration->>Database: 인덱스 생성
  Database-->>Flyway: 마이그레이션 성공
  Flyway-->>SpringBoot: 애플리케이션 시작 계속
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • DSM-PICK/PiCK_CORE_SERVER#665: 요청된 "DB 버전 관리 툴 적용(Flyway)" 기능을 직접 구현하며, 의존성, 빌드 설정, 애플리케이션 설정, 마이그레이션 파일 통합을 모두 포함.

Possibly related PRs

  • DSM-PICK/PiCK_CORE_SERVER#501: 검색된 PR은 tbl_user/tbl_admin 외래키 및 인덱스를 추가하는 V2 마이그레이션을 포함하는데, 현재 PR에서 이들 변경이 V1 baseline으로 통합되면서 기존 V2 마이그레이션 파일 삭제로 인해 직접적으로 영향을 받음.

Suggested reviewers

  • imhanseong

Poem

🐰 Flyway 친구가 왔네요,
버전 관리 시작해봐요,
스키마는 정렬되고,
마이그레이션 흐르고,
데이터베이스 든든하네요! 🗄️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목은 주요 변경 사항인 Flyway 데이터베이스 버전 관리 툴 적용을 명확하게 설명하고 있습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 665-db-버전-관리-툴-적용

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

🤖 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 @.gitignore:
- Line 47: 현재 .gitignore에 있는 예외 규칙 "!.idea/fileTemplates"는 디렉터리만 제외하고 하위 파일은 계속
무시될 수 있으니, .gitignore에서 예외를 디렉터리와 그 내부 모든 파일로 확장하도록 "!.idea/fileTemplates/"와
"!.idea/fileTemplates/**" 같은 패턴을 추가해 하위 템플릿 파일들이 실제로 unignore 되게 수정하세요 (기존에
".idea/" 전체를 무시하는 규칙이 있으면 해당 규칙 이후에 이 예외들을 배치하세요).

In `@src/main/resources/application.yaml`:
- Around line 55-56: The Flyway setting baseline-on-migrate is hardcoded true
which weakens safety; change baseline-on-migrate to false (or remove the key to
use default false) in application.yaml and only enable it explicitly per
environment where needed, and keep baseline-version as-is if used; ensure any
environment-specific activation is done via profile-specific YAML or environment
variables rather than the global application.yaml.

In `@src/main/resources/db/migration/V202605142000__Drop_User.sql`:
- Line 1: The migration DROP TABLE `user` must be made idempotent to avoid
failures when the table is already absent; update the migration
(V202605142000__Drop_User.sql) to use DROP TABLE IF EXISTS `user` so the
statement succeeds harmlessly if the table doesn't exist.
🪄 Autofix (Beta)

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 606acfdb-62de-4fb6-90e7-df20a6ca1633

📥 Commits

Reviewing files that changed from the base of the PR and between dfb6279 and 544aa83.

📒 Files selected for processing (13)
  • .gitignore
  • .idea/fileTemplates/Flyway Migration Templates.sql
  • build.gradle.kts
  • buildSrc/src/main/kotlin/Dependencies.kt
  • src/main/resources/application.yaml
  • src/main/resources/db/migration/V1__baseline.sql
  • src/main/resources/db/migration/V202605142000__Drop_User.sql
  • src/main/resources/db/migration/V2_add_move_column_to_classroom.sql
  • src/main/resources/db/migration/V2_entity_mapping_admin.sql
  • src/main/resources/db/migration/V2_entity_mapping_user.sql
  • src/main/resources/db/migration/V3_add_unique_constraint_to_weekend_meal_period_admin_id.sql
  • src/main/resources/db/migration/V3_create_device_token_tables.sql
  • src/main/resources/db/migration/V4_add_unique_constraint_to_meal_date_and_type.sql
💤 Files with no reviewable changes (6)
  • src/main/resources/db/migration/V3_add_unique_constraint_to_weekend_meal_period_admin_id.sql
  • src/main/resources/db/migration/V2_entity_mapping_admin.sql
  • src/main/resources/db/migration/V2_add_move_column_to_classroom.sql
  • src/main/resources/db/migration/V4_add_unique_constraint_to_meal_date_and_type.sql
  • src/main/resources/db/migration/V2_entity_mapping_user.sql
  • src/main/resources/db/migration/V3_create_device_token_tables.sql

Comment thread .gitignore
.env

### File Template ###
!.idea/fileTemplates

@coderabbitai coderabbitai Bot May 15, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

.idea/fileTemplates 예외 규칙이 하위 파일까지 해제되지 않습니다.

현재 패턴은 디렉터리 경로만 예외 처리해서, 실제 템플릿 파일(.idea/fileTemplates/**)은 계속 ignore 될 수 있습니다.

🔧 제안 수정
-!.idea/fileTemplates
+!.idea/fileTemplates/
+!.idea/fileTemplates/**
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
!.idea/fileTemplates
!.idea/fileTemplates/
!.idea/fileTemplates/**
🤖 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 @.gitignore at line 47, 현재 .gitignore에 있는 예외 규칙 "!.idea/fileTemplates"는 디렉터리만
제외하고 하위 파일은 계속 무시될 수 있으니, .gitignore에서 예외를 디렉터리와 그 내부 모든 파일로 확장하도록
"!.idea/fileTemplates/"와 "!.idea/fileTemplates/**" 같은 패턴을 추가해 하위 템플릿 파일들이 실제로
unignore 되게 수정하세요 (기존에 ".idea/" 전체를 무시하는 규칙이 있으면 해당 규칙 이후에 이 예외들을 배치하세요).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

계속 ignore되지 않고 잘 예외처리 되어 이미 깃에 커밋했습니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@ByunDohwi, 확인해 주셔서 감사합니다! 현재 .gitignore 설정에서 .idea/*로 상위 디렉터리를 무시하고 있기 때문에 !.idea/fileTemplates 패턴만으로도 해당 디렉터리 및 하위 파일들이 올바르게 예외 처리되는 것을 확인하셨군요. 기존 설정 그대로 유지해도 문제없겠습니다. 🐇

Comment on lines +55 to +56
baseline-on-migrate: true
baseline-version: 1

@coderabbitai coderabbitai Bot May 15, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Redgate Flyway 공식 문서에서 baselineOnMigrate의 동작과 "removes the safety net" 경고 문구를 확인해 주세요.

💡 Result:

Redgate Flyway 공식 문서에 따르면, baselineOnMigrate는 migrate 명령 실행 시 스키마가 비어 있지 않고 schema history table이 없을 때 자동으로 baseline을 호출하는 설정입니다[1][2]. 이 설정을 활성화하면 baselineVersion으로 스키마를 baseline한 후 해당 버전 이상의 마이그레이션만 적용합니다[1]. 이는 기존 DB를 가진 초기 프로덕션 배포에서 별도의 baseline 단계를 생략하는 편의 기능입니다[1]. 문서에는 "Be careful when enabling this as it removes the safety net that ensures Flyway does not migrate the wrong database in case of a configuration mistake!"라는 경고 문구가 명시되어 있습니다[1][2]. 이는 구성 오류로 잘못된 데이터베이스에 마이그레이션이 적용되는 것을 방지하는 안전 장치를 제거한다는 의미입니다. 기본값은 false이며, CLI 예시: flyway -baselineOnMigrate=true migrate[1].

Citations:


🏁 Script executed:

cat -n src/main/resources/application.yaml | sed -n '50,65p'

Repository: DSM-PICK/PiCK_CORE_SERVER

Length of output: 647


🏁 Script executed:

find . -name "application*.yaml" -o -name "application*.yml" | head -20

Repository: DSM-PICK/PiCK_CORE_SERVER

Length of output: 107


baseline-on-migrate 상시 활성화는 운영 안전장치를 약화시킵니다.

Flyway 공식 문서는 baselineOnMigrate 활성화 시 "Be careful when enabling this as it removes the safety net that ensures Flyway does not migrate the wrong database in case of a configuration mistake!"라고 명시하고 있습니다. 현재 코드에서 이 옵션이 true로 하드코딩되어 있어, 히스토리 테이블이 없는 비어있지 않은 DB를 자동 baseline 처리하면서 잘못된 대상 DB를 조기에 감지하기 어렵습니다. 기본값(false)을 유지하고 필요한 환경에서만 명시적으로 활성화하는 편이 안전합니다.

🔧 제안 수정
     flyway:
         enabled: true
-        baseline-on-migrate: true
+        baseline-on-migrate: ${FLYWAY_BASELINE_ON_MIGRATE:false}
         baseline-version: 1
         locations:
             - classpath:db/migration
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
baseline-on-migrate: true
baseline-version: 1
baseline-on-migrate: ${FLYWAY_BASELINE_ON_MIGRATE:false}
baseline-version: 1
🤖 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/application.yaml` around lines 55 - 56, The Flyway setting
baseline-on-migrate is hardcoded true which weakens safety; change
baseline-on-migrate to false (or remove the key to use default false) in
application.yaml and only enable it explicitly per environment where needed, and
keep baseline-version as-is if used; ensure any environment-specific activation
is done via profile-specific YAML or environment variables rather than the
global application.yaml.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

이미 DB가 존재하는 상황에서 추가하는 부분이기 때문에 첫 도입시에는 baseline-on-migrate: true가 필요합니다. flyway 적용 후 false로 다시 변경하겠습니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@ByunDohwi, 말씀하신 내용이 맞습니다. 기존 DB에 Flyway를 처음 도입할 때는 flyway_schema_history 테이블이 없는 비어있지 않은 스키마를 처리하기 위해 baseline-on-migrate: true가 필요합니다.

다만 초기 적용 이후 false로 되돌리는 작업이 누락되지 않도록 별도 이슈나 TODO로 트래킹해 두시길 권장드립니다. 혹시 지금 바로 추적용 이슈를 생성해 드릴까요?

(๑・ω・๑) 🐇

@ByunDohwi
ByunDohwi merged commit b9faa08 into develop May 15, 2026
1 check passed
@ByunDohwi
ByunDohwi deleted the 665-db-버전-관리-툴-적용 branch May 15, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

프로젝트 세팅 프로젝트 세팅

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DB 버전 관리 툴 적용

2 participants