-
Notifications
You must be signed in to change notification settings - Fork 0
[infra] flyway 기반 DB 마이그레이션 도입 & Room 테이블에 RoomStatus 컬럼 추가 #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
de5dbb3
71d1096
1b1f6cf
1d5eeb1
0219ab4
1d39c20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,6 +50,11 @@ public class RoomJpaEntity extends BaseJpaEntity { | |||||||||||||||
| @Column(name = "member_count",nullable = false) | ||||||||||||||||
| private int memberCount = 1; | ||||||||||||||||
|
|
||||||||||||||||
| @Builder.Default | ||||||||||||||||
| @Column(name = "room_status", nullable = false) | ||||||||||||||||
| @Enumerated(EnumType.STRING) | ||||||||||||||||
| private RoomStatus roomStatus = RoomStatus.RECRUITING; | ||||||||||||||||
|
|
||||||||||||||||
| @ManyToOne(fetch = FetchType.LAZY) | ||||||||||||||||
| @JoinColumn(name = "book_id", nullable = false) | ||||||||||||||||
| private BookJpaEntity bookJpaEntity; | ||||||||||||||||
|
|
@@ -68,6 +73,7 @@ public RoomJpaEntity updateFrom(Room room) { | |||||||||||||||
| this.endDate = room.getEndDate(); | ||||||||||||||||
| this.recruitCount = room.getRecruitCount(); | ||||||||||||||||
| this.memberCount = room.getMemberCount(); | ||||||||||||||||
| this.roomStatus = room.getRoomStatus(); | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updateFrom에서 roomStatus null 덮어쓰기 방지 room.getRoomStatus()가 null이면 @column(nullable=false) 위반 가능성이 큽니다. null일 때는 필드 유지(또는 예외)하도록 가드하세요. 적용 diff: - this.roomStatus = room.getRoomStatus();
+ if (room.getRoomStatus() != null) {
+ this.roomStatus = room.getRoomStatus();
+ }
+ // null을 허용하지 않으려면 다음처럼 실패 빠르게도 고려:
+ // Objects.requireNonNull(room.getRoomStatus(), "roomStatus must not be null");📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| return this; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||||||||||||||||||||||||||||
| package konkuk.thip.room.adapter.out.jpa; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public enum RoomStatus { | ||||||||||||||||||||||||||||||
| RECRUITING, | ||||||||||||||||||||||||||||||
| IN_PROGRESS, | ||||||||||||||||||||||||||||||
| EXPIRED | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 패키지 레이어링 역참조(도메인→어댑터) 발생 Room 도메인이 adapter.out.jpa 패키지의 enum을 import합니다. 도메인이 하위 레이어를 참조하지 않도록 RoomStatus를 도메인(or common) 레이어로 승격하고, JPA 엔티티가 그 도메인 enum을 사용하도록 방향을 정리하세요. 예(이 PR 외 파일 변경 수반): - package konkuk.thip.room.adapter.out.jpa;
+ package konkuk.thip.room.domain;그리고 Room/RoomJpaEntity/Mapper의 import를 도메인 enum으로 교체. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coderabbitai enum 의존성은 유연하게 진행하기로 결정했어 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @seongjunnoh 네, 알겠습니다! enum 의존성에 대해 유연하게 접근하기로 하신 결정을 이해했어요. 실용적인 구현을 우선시하는 방향으로 진행하시는군요. (・ω・) ♪ ✏️ Learnings added
🧠 Learnings used
Comment on lines
+3
to
+7
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굳굳
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굳굳 |
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||
| import konkuk.thip.common.exception.InvalidStateException; | ||||||||
| import konkuk.thip.common.entity.StatusType; | ||||||||
| import konkuk.thip.common.exception.code.ErrorCode; | ||||||||
| import konkuk.thip.room.adapter.out.jpa.RoomStatus; | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 도메인에서 어댑터 enum import 회피 필요 도메인 레이어가 adapter 패키지를 참조하지 않도록 RoomStatus를 도메인(or common)으로 이동시킨 뒤 import를 교체하세요. - import konkuk.thip.room.adapter.out.jpa.RoomStatus;
+ import konkuk.thip.room.domain.RoomStatus; // enum을 도메인으로 이동했다고 가정📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| import konkuk.thip.room.domain.value.Category; | ||||||||
| import lombok.Getter; | ||||||||
| import lombok.experimental.SuperBuilder; | ||||||||
|
|
@@ -40,6 +41,8 @@ public class Room extends BaseDomainEntity { | |||||||
|
|
||||||||
| private int memberCount; | ||||||||
|
|
||||||||
| private RoomStatus roomStatus; | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니다! 도메인 entity 도 그냥 enum 자체를 의존하는게 더 나을 것 같습니다!! 현재 도메인 entity 에서 String 타입으로 enum을 의존하는 코드들도 수정하는게 좋을듯 하네요
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅜㅜ |
||||||||
|
|
||||||||
| private Long bookId; | ||||||||
|
|
||||||||
| private Category category; | ||||||||
|
|
@@ -62,6 +65,7 @@ public static Room withoutId(String title, String description, boolean isPublic, | |||||||
| .endDate(endDate) | ||||||||
| .recruitCount(recruitCount) | ||||||||
| .memberCount(1) // 처음 Room 생성 시 방장 1명 | ||||||||
| .roomStatus(RoomStatus.RECRUITING) // 처음 Room 생성 시 -> 모집중 | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋네여 LGTM |
||||||||
| .bookId(bookId) | ||||||||
| .category(category) | ||||||||
| .build(); | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| -- 1) 컬럼 추가: 기본값 RECRUITING, NOT NULL | ||
| ALTER TABLE rooms | ||
| ADD COLUMN room_status VARCHAR(32) NOT NULL DEFAULT 'RECRUITING' | ||
| COMMENT 'Room 상태: RECRUITING/IN_PROGRESS/EXPIRED'; | ||
|
|
||
| -- 2) start_date가 현재 날짜보다 "이전"이면 IN_PROGRESS로 업데이트 | ||
| UPDATE rooms | ||
| SET room_status = 'IN_PROGRESS' | ||
| WHERE start_date <= CURDATE(); | ||
|
|
||
| -- 3) end_date가 현재 날짜보다 "이전"이면 EXPIRED로 업데이트 | ||
| UPDATE rooms | ||
| SET room_status = 'EXPIRED' | ||
| WHERE end_date < CURDATE(); | ||
|
Comment on lines
+1
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 테스트(H2) 환경 호환성 주의 이 스크립트는 MySQL 전용 문법(CURDATE, COMMENT)을 사용합니다. H2에서 Flyway가 실행되면 실패할 수 있습니다. 파일을 MySQL 전용으로 분기(.mysql.sql)하거나 테스트 프로필에서 Flyway 적용을 비활성/분리하세요. 예:
🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
room_status 매핑은 적절. 다만 null 유입 방지(Bean Validation) 추가 필요
@Builder.Default만으로는 빌더가 명시적으로 null을 넣을 때/기본 생성자로 생성 후 세터로 null이 들어갈 때를 막지 못합니다. DB 제약(nullable=false) 위반 또는 INSERT 실패를 예방하려면 @NotNull을 붙여 조기 검증을 권장합니다.
적용 diff:
추가 import(변경 범위 밖):
추가로, 생성 경로가 빌더가 아닌 경우를 대비해 PrePersist 가드도 고려 가능합니다(변경 범위 밖):
🤖 Prompt for AI Agents
💡 Verification agent
🧩 Analysis chain
계층 의존 역전 가능성: RoomStatus의 패키지 위치 재검토
Enum이 adapter.out.jpa 패키지에 있고, 도메인 객체(Room)가 이를 직접 참조하면 도메인→인프라 의존이 생깁니다. Enum을 도메인 계층(e.g., konkuk.thip.room.domain.value.RoomStatus)으로 승격하거나, 도메인 Enum ↔ JPA Enum 매핑을 명확히 분리해 주세요.
아래 스크립트로 도메인 계층이 adapter의 RoomStatus를 import하는지 확인해 주세요:
🏁 Script executed:
Length of output: 1028
도메인 계층이 infra(adapter) enum을 직접 참조하지 않도록 분리 필요
Room.java(도메인)에서
konkuk.thip.room.adapter.out.jpa.RoomStatus를 import(Line 7)해 도메인→인프라 의존이 발생하고 있습니다.src/main/java/konkuk/thip/room/domain/value패키지에 도메인 전용RoomStatusenum을 선언@Enumerated필드 매핑 시 도메인 enum ↔ JPA enum 간 변환 로직(또는 AttributeConverter)을 구현하세요.🤖 Prompt for AI Agents