Skip to content

[FEAT] Flyway 기반 DB 스키마 관리 도입#286

Merged
kjhyeon0620 merged 3 commits into
develop-demofrom
feat/#285-flyway-migration-setup
Jun 5, 2026
Merged

[FEAT] Flyway 기반 DB 스키마 관리 도입#286
kjhyeon0620 merged 3 commits into
develop-demofrom
feat/#285-flyway-migration-setup

Conversation

@kjhyeon0620

@kjhyeon0620 kjhyeon0620 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

📄 작업 내용 요약

  • Flyway 기반 DB 마이그레이션 설정 추가
  • 초기 스키마 및 category seed 데이터를 Flyway로 관리
  • 알라딘 도서 ISBN 유니크 인덱스 추가
  • 기존 Hibernate 컬럼/제약 정리
  • ddl-auto 기본값을 validate로 변경

📎 Issue 번호


✅ 작업 목록

  • 기능 구현
  • 코드 리뷰 반영
  • 테스트 코드 작성
  • 문서 업데이트

📝 기타 참고사항

Summary by CodeRabbit

릴리스 노트

  • 데이터베이스 개선

    • 데이터베이스 스키마 관리 시스템을 개선하여 더욱 안정적인 초기화 및 업데이트 프로세스 구현
    • 카테고리 초기 데이터 설정 로직 정리 및 재구성
  • 구성 변경

    • 데이터베이스 검증 모드 적용으로 스키마 관리 강화

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kjhyeon0620, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 39 minutes and 16 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: acaa5a09-7f16-4831-a295-d9126359bf28

📥 Commits

Reviewing files that changed from the base of the PR and between cc0511e and 9d02451.

📒 Files selected for processing (6)
  • src/main/resources/db/migration/V1__init_schema.sql
  • src/test/java/app/nook/book/repository/BookRepositoryTest.java
  • src/test/java/app/nook/book/repository/SearchHistoryRepositoryTest.java
  • src/test/java/app/nook/focus/repository/FocusRepositoryTest.java
  • src/test/java/app/nook/focus/repository/ThemeRepositoryTest.java
  • src/test/resources/application-test.yml

Walkthrough

Hibernate의 자동 스키마 관리에서 Flyway 기반 버전 제어 마이그레이션으로 전환합니다. 의존성과 설정을 추가하고, 현재 스키마를 초기 마이그레이션으로 정의한 후 제약 및 인덱스를 최적화하는 마이그레이션을 순차적으로 적용합니다.

Changes

Flyway 마이그레이션 도입

Layer / File(s) Summary
Flyway 의존성 및 설정
build.gradle, src/main/resources/application.yml
Flyway 라이브러리(flyway-core, flyway-database-postgresql)를 추가하고, JPA의 ddl-auto 정책을 update에서 validate로 변경하며, Flyway 마이그레이션 위치, 기준 버전, baseline 설정을 환경변수로 구성합니다.
초기 스키마 마이그레이션
src/main/resources/db/migration/V1__init_schema.sql
10개 도메인 테이블(category, book, users, search_history, library, themes, focuses, records, record_images, book_timelines)을 생성하고 외래 키, 유니크 제약, 인덱스를 정의하며, 초기 카테고리 데이터를 ON CONFLICT 업서트로 삽입합니다.
스키마 최적화 및 정리
src/main/resources/db/migration/V2__add_unique_index_for_aladin_book_isbn.sql, src/main/resources/db/migration/V3__cleanup_legacy_hibernate_schema.sql
V2에서 Aladin 도서의 ISBN13 유니크 인덱스를 추가하고, V3에서 레거시 컬럼(cover_image_url, profile_url)을 제거하며, library.page를 NOT NULL로 전환하고, 기존 체크 제약들을 정리합니다.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 마이그레이션의 길을 열며
Flyway와 함께 스키마를 춤추니
옛날의 auto 방식은 안녕히
버전 제어가 반기는 DB 변천사 ✨

🚥 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 기반 DB 스키마 관리 도입이라는 주요 변경사항을 명확하게 요약하고 있습니다.
Linked Issues check ✅ Passed 모든 주요 목표가 구현되었습니다: ddl-auto를 validate로 변경, 초기 마이그레이션 작성, ISBN 유니크 인덱스 추가, CategoryInitializer 제거.
Out of Scope Changes check ✅ Passed 모든 변경사항이 Flyway 마이그레이션 도입 범위 내에 있으며, 연관된 이슈 #285의 목표와 일치합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 feat/#285-flyway-migration-setup

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

🧹 Nitpick comments (1)
src/main/resources/db/migration/V1__init_schema.sql (1)

6-10: ⚡ Quick win

uk_category_mall_type_name와 같은 키에 인덱스를 하나 더 만들고 있습니다.

Line 6의 UNIQUE 제약이 이미 같은 컬럼 순서의 접근 경로를 제공하므로, Line 9-10 인덱스는 쓰기 비용과 저장 공간만 추가할 가능성이 큽니다. 하나만 남기는 편이 낫습니다.

정리 예시
 CREATE TABLE category (
     category_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
     category_name VARCHAR(50),
     mall_type VARCHAR(255),
     aladin_category_id INTEGER NOT NULL,
     CONSTRAINT uk_category_mall_type_name UNIQUE (mall_type, category_name)
 );
-
-CREATE INDEX idx_category_malltype_name
-    ON category (mall_type, category_name);
🤖 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/V1__init_schema.sql` around lines 6 - 10, The
migration creates a UNIQUE constraint uk_category_mall_type_name on (mall_type,
category_name) and then redundantly creates a separate index
idx_category_malltype_name on the same columns; remove the duplicate index
creation (the CREATE INDEX idx_category_malltype_name ... ON category
(mall_type, category_name); lines) and keep the UNIQUE constraint
uk_category_mall_type_name so you avoid extra write/storage cost while
preserving the same access path.
🤖 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/application.yml`:
- Around line 25-29: The Flyway config in application.yml enables migrations by
default (flyway.enabled / ${FLYWAY_ENABLED:true}) which can run
PostgreSQL-specific scripts against the H2 test DB; to fix, disable Flyway in
the test profile by setting spring.flyway.enabled=false (or
FLyWAY_ENABLED=false) in application-test.yml, or split the test profile to use
PostgreSQL/Testcontainers so that flyway.locations and baseline settings in
application.yml only run against the intended Postgres environment; update
application-test.yml to explicitly override flyway.enabled accordingly.

In
`@src/main/resources/db/migration/V2__add_unique_index_for_aladin_book_isbn.sql`:
- Around line 1-4: The partial unique index ux_book_aladin_isbn13 in
V2__add_unique_index_for_aladin_book_isbn.sql can fail if duplicate rows already
exist for (source_type='ALADIN' AND isbn13 IS NOT NULL); add a safe
pre-migration that detects and resolves duplicates (e.g., run the provided GROUP
BY SELECT to find duplicates and a cleanup step that keeps one row per isbn13 —
e.g., delete others by id or merge data), then create the unique index using
CREATE UNIQUE INDEX CONCURRENTLY ux_book_aladin_isbn13 ON book(isbn13) WHERE
source_type='ALADIN' AND isbn13 IS NOT NULL in a follow-up migration so Flyway
won’t fail on existing duplicates and the index is built safely.

---

Nitpick comments:
In `@src/main/resources/db/migration/V1__init_schema.sql`:
- Around line 6-10: The migration creates a UNIQUE constraint
uk_category_mall_type_name on (mall_type, category_name) and then redundantly
creates a separate index idx_category_malltype_name on the same columns; remove
the duplicate index creation (the CREATE INDEX idx_category_malltype_name ... ON
category (mall_type, category_name); lines) and keep the UNIQUE constraint
uk_category_mall_type_name so you avoid extra write/storage cost while
preserving the same access path.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1679c029-fc07-46aa-9c4f-4df07c778d81

📥 Commits

Reviewing files that changed from the base of the PR and between 2cc34d1 and cc0511e.

📒 Files selected for processing (6)
  • build.gradle
  • src/main/java/app/nook/book/init/CategoryInitializer.java
  • src/main/resources/application.yml
  • src/main/resources/db/migration/V1__init_schema.sql
  • src/main/resources/db/migration/V2__add_unique_index_for_aladin_book_isbn.sql
  • src/main/resources/db/migration/V3__cleanup_legacy_hibernate_schema.sql
💤 Files with no reviewable changes (1)
  • src/main/java/app/nook/book/init/CategoryInitializer.java

Comment thread src/main/resources/application.yml
@JiwonLee42

Copy link
Copy Markdown
Contributor
Overall Project 67.79% 🍏

There is no coverage information present for the Files changed

@kjhyeon0620 kjhyeon0620 merged commit 505015b into develop-demo Jun 5, 2026
5 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.

[FEAT] Flyway 기반 마이그레이션 도입

2 participants