-
Notifications
You must be signed in to change notification settings - Fork 2
Feat : DB 시딩 파일 추가 #82
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
base: develop
Are you sure you want to change the base?
Conversation
|
""" Walkthrough이 변경사항은 데이터베이스 초기화 및 시딩을 위한 SQL 스크립트 세트를 도입 및 갱신합니다. 스키마 정의( Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40분
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Pull Request Overview
DB 스키마를 최신화하고 초기 데이터 시딩을 위한 SQL 파일들을 추가하는 PR입니다. 개발 환경에서 테스트를 위한 샘플 데이터를 제공하여 각 도메인별 기능 검증이 가능하도록 합니다.
- 데이터베이스 스키마 파일을 최신 엔터티 구조에 맞게 업데이트
- 기본적인 테스트 데이터를 포함한 init.sql 파일 추가
- 더 상세한 17기 기준 샘플 데이터를 포함한 init-250724.sql 파일 추가
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/main/resources/db/schema.sql | 기존 스키마를 최신 엔터티 구조에 맞게 전면 개편하고 외래키 제약조건 추가 |
| src/main/resources/db/init.sql | 각 테이블별 기본 테스트 데이터 추가 |
| src/main/resources/db/init-250724.sql | 17기 기준 20명의 멤버와 상세한 도메인별 샘플 데이터 추가 |
sequenceDiagram
participant Dev as 개발자
participant DB as 데이터베이스
participant App as 애플리케이션
Dev->>DB: schema.sql 실행
Note over DB: 테이블 구조 생성
Dev->>DB: init.sql 또는 init-250724.sql 실행
Note over DB: 샘플 데이터 삽입
App->>DB: 도메인별 기능 테스트
DB-->>App: 시딩된 데이터 반환
Comments suppressed due to low confidence (2)
src/main/resources/db/schema.sql:147
- [nitpick] refresh_tokens 테이블에서
TEXT타입이 대문자로 사용되었는데, 다른 테이블들에서는varchar(255)등 소문자로 일관되게 사용되고 있습니다. 코틀린과 SQL 스타일 가이드에 따라text로 소문자를 사용하는 것이 좋겠습니다. 기존 코드와 비교했을 때 대소문자 통일성이 부족합니다.
token TEXT,
| (18, 9, 18, b'0', b'1', '2024-01-07 10:00:00', '2024-01-07 10:00:00', NULL, NULL), | ||
| (19, 10, 19, b'1', b'1', '2024-01-08 10:00:00', '2024-01-08 10:00:00', NULL, NULL), | ||
| (20, 10, 20, b'0', b'0', '2024-01-08 10:00:00', '2024-01-08 10:00:00', NULL, NULL), | ||
| (21, 10, 20, b'0', b'0', '2024-01-08 10:00:00', '2024-01-08 10:00:00', NULL, NULL), |
Copilot
AI
Jul 24, 2025
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.
gathering_members 테이블에서 167-182번 라인에 동일한 member_id(20)가 여러 번 반복되고, 같은 날짜와 시간이 계속 사용되고 있습니다. 이는 실제 데이터와 차이가 있고 유지보수가 어렵습니다. 각각 다른 멤버들과 다른 시간대를 사용하거나, 실제 gathering_id에 맞는 적절한 멤버들을 배치하는 것이 좋겠습니다. 현재 방식은 데이터의 의미를 파악하기 어렵고 테스트 시 혼란을 야기할 수 있습니다.
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.
Actionable comments posted: 5
🧹 Nitpick comments (3)
src/main/resources/db/init.sql (1)
46-53: 계좌정보 예시 데이터 최소 검증 필요
bank_name,bill_account_value값에 실제 포맷(숫자·‘-’) 검증 로직이 스키마/애플리케이션 레이어에 존재하지 않으면, 잘못된 형식의 데이터가 그대로 유입될 수 있습니다.
도메인 제약조건(길이, 정규식 등)을 추가로 고려해 주세요.src/main/resources/db/init-250724.sql (1)
145-182: 과도한 중복 Gathering Member 레코드
gathering_id = 20,member_id = 20조합이 10회 이상 반복됩니다.
기능적으로는 PK(gathering_member_id)로 구별되지만 실제 서비스 데이터로 사용하기엔 비현실적이며, 통계/로직 오동작의 가능성이 있습니다.
테스트용 중복인지, 의도된 시나리오인지 다시 검토해주세요.src/main/resources/db/schema.sql (1)
185-187: Gathering Receipts 에 단일 영수증만 허용됨
UKm6ed9w2qvce73flgh19rskk9t (gathering_id)제약은 한 회식당 영수증 1건만 허용합니다.
서비스 정책상 여러 영수증을 지원해야 한다면 UNIQUE 제약을 제거하고 인덱스로만 유지하세요.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/resources/db/init-250724.sql(1 hunks)src/main/resources/db/init.sql(1 hunks)src/main/resources/db/schema.sql(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: depromeet/dpm-core-server#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-21T15:22:12.408Z
Learning: 가장 먼저, 코드 리뷰 시 PR에 대한 요약을 작성하고, 작성된 코드의 시퀀스 다이어그램을 그려서 첨부한다
🔇 Additional comments (1)
src/main/resources/db/init-250724.sql (1)
53-72: ROLE 매핑이 설명과 불일치주석에는 “운영진은 ROLE_ADMIN, 나머지는 ROLE_USER”라 되어 있으나
member_id14(운영진) →20 →authority_id = 1(ROLE_USER)
member_id17authority_id = 2(ROLE_ADMIN) 로 역으로 입력되어 있습니다.
도메인 정책을 따른 값으로 재확인 바랍니다.
| -- Cohorts (기수) | ||
| INSERT INTO cohorts (cohort_id, created_at, updated_at, value) VALUES | ||
| (1, 1710000000, 1710000000, '17'), | ||
| (2, 1700000000, 1700000000, '16'); | ||
|
|
||
| -- Teams (팀) | ||
| INSERT INTO teams (team_id, cohort_id, number, created_at, updated_at) VALUES | ||
| (1, 1, 1, 1710000000, 1710000000), | ||
| (2, 1, 2, 1710000000, 1710000000); | ||
|
|
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.
초기화 스크립트 간 PK 충돌 위험
본 init.sql은 PK 값이 1부터 고정되어 있습니다. 동일한 PK 값을 갖는 init-250724.sql도 PR에 포함되어 있어 두 스크립트를 연속 실행하면 PRIMARY KEY duplication 오류가 발생합니다.
운영·로컬 환경별로 하나만 실행되도록 분리하거나, INSERT ... ON DUPLICATE KEY IGNORE/시퀀스 리셋 전략을 명확히 정의해주세요.
🤖 Prompt for AI Agents
In src/main/resources/db/init.sql lines 1 to 10, the primary key values for
cohorts and teams start fixed at 1, which conflicts with another script
init-250724.sql causing duplicate key errors when both run sequentially. To fix
this, modify the insert statements to either use INSERT ... ON DUPLICATE KEY
IGNORE syntax or implement a sequence reset strategy to avoid PK collisions.
Alternatively, separate the scripts so only one runs per environment, ensuring
no overlapping PK values.
| create table if not exists cohorts ( | ||
| cohort_id bigint not null auto_increment, | ||
| created_at bigint not null, | ||
| updated_at bigint not null, | ||
| value varchar(255) not null, | ||
| primary key (cohort_id) | ||
| ) engine=InnoDB; | ||
|
|
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
Timestamp 타입 불일치(Cohorts)
cohorts.created_at/updated_at 는 bigint, 대부분 다른 테이블은 datetime(6)을 사용합니다.
같은 의미의 컬럼은 동일 타입으로 맞춰야 쿼리·ORM 매핑·비교 연산에서 혼선을 줄일 수 있습니다.
🤖 Prompt for AI Agents
In src/main/resources/db/schema.sql around lines 45 to 52, the created_at and
updated_at columns in the cohorts table are defined as bigint, while most other
tables use datetime(6) for these timestamp fields. To maintain consistency and
avoid confusion in queries, ORM mapping, and comparisons, change the data types
of cohorts.created_at and cohorts.updated_at from bigint to datetime(6).
| create table if not exists sessions ( | ||
| is_online bit not null, | ||
| week integer not null, | ||
| attendance_start datetime(6) not null, | ||
| cohort_id bigint not null, | ||
| date datetime(6) not null, | ||
| session_id bigint not null auto_increment, | ||
| attendance_code varchar(255) not null, | ||
| event_name varchar(255), | ||
| place varchar(255), | ||
| primary key (session_id) | ||
| ) engine=InnoDB; |
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
참조 무결성 제약 부족
attendances, member_authorities, member_teams 등 다수 테이블이 외래키 없이 정의되어 있습니다.
데이터 품질을 위해 다음 FK 추가를 고려해 주세요.
ALTER TABLE attendances
ADD FOREIGN KEY (member_id) REFERENCES members(member_id),
ADD FOREIGN KEY (session_id) REFERENCES sessions(session_id);
-- 동일 패턴으로 다른 테이블도 추가🤖 Prompt for AI Agents
In src/main/resources/db/schema.sql around lines 160 to 171, the sessions table
and other related tables like attendances, member_authorities, and member_teams
lack foreign key constraints, which can lead to data integrity issues. To fix
this, add appropriate foreign key constraints linking columns such as member_id
and session_id in these tables to their referenced primary keys in members and
sessions tables respectively. Use ALTER TABLE statements to define these foreign
keys to enforce referential integrity and improve data quality.
| number integer not null, | ||
| cohort_id bigint not null, | ||
| created_at bigint not null, | ||
| team_id bigint not null auto_increment, | ||
| updated_at bigint not null, | ||
| primary key (team_id) |
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
Timestamp 타입 불일치(Teams)
teams.created_at/updated_at 도 bigint입니다. 위 코멘트와 동일한 이유로 datetime(6) 사용을 권장합니다.
🤖 Prompt for AI Agents
In src/main/resources/db/schema.sql around lines 174 to 179, the columns
created_at and updated_at in the teams table are currently defined as bigint,
which is inconsistent with the recommended datetime(6) type. Change the data
types of created_at and updated_at from bigint to datetime(6) to ensure proper
timestamp handling and consistency with other tables.
LeeHanEum
left a comment
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.
LGTM 👍👍
its-sky
left a comment
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.
LGTM!!
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; | ||
| create table if not exists attendances ( | ||
| attended_at datetime(6), | ||
| id bigint not null auto_increment, |
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.
컬럼명 session_id로 부탁드려요~
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.
이거 시딩 파일은 1차 끝나고 저희 만나서 얘기해보고 정책 맞추면 어떨까 싶어용 ㅎㅎ
Summary
Tasks
ETC
각자 맡은 도메인의 데이터 확인해주세요.
insert는 제대로 되지만, 도메인 정책 상 나올 수 없는 케이스는 막을 수가 없고 제가 전부 체크할 수가 없어서 각자 도메인 정책에 따라서 수정해주셔야 할 거 같아요.
정산 쪽도 수정중입니다!
Screenshot
Summary by CodeRabbit
신규 기능
리팩터링