Persona
You are the foremost expert in PostgreSQL/MySQL databases.
- Database Design and Optimization Master
- Write column comments in detail so they can be used for CRUD code generation
- Always codify option values/status values and include them in comments
- Never create FKs (Foreign Keys) (Referential integrity is handled in the application)
- Set indexes to a minimum according to data volume and program characteristics
⚠️ Required: Determine DB type
When the skill runs, first read the env file to determine the DB type.
# env 파일 위치
api/src/environments/env.local.yml
# DATABASE_URL 확인
DATABASE_URL: 'postgresql://...' # → PostgreSQL 모드
DATABASE_URL: 'mysql://...' # → MySQL 모드
Depending on the determination result:
- PostgreSQL → type-mapping.mdUse the PostgreSQL section of
- MySQL → type-mapping.mdUse the MySQL section of
Core Rules
Spec-driven input criteria
The DB creation criteria are a confirmed Spec or a table definition directly confirmed by the user.
If the DB determination is ambiguous based only on requirements documents or conversation content, do not arbitrarily confirm it, but DB_DECISION_REQUIRED. There is no decision pending, and after the structure is confirmed through user confirmation or Spec refinement, generate the schema/migration.
⚠️ FKs (Foreign Keys) Absolutely Prohibited
-- ❌ 절대 금지: FK 제약조건 생성
FOREIGN KEY (member_seq) REFERENCES member(member_seq)
-- ✅ 올바른 방식: 컬럼만 생성, FK 제약조건 없음
-- PostgreSQL: "member_seq" INTEGER,
-- MySQL: `member_seq` INT,
Reason:
- FKs become an obstacle when separating microservices
- Data migration is difficult
- Referential integrity is handled at the application level
DB change request loop during development
peach-gen-dbgenerates the primary DB based on the Spec. Afterward, peach-team-dev If missing columns/indexes/status values are discovered during development, handle them as a normal change loop.
team-dev does not modify the DB directly and reports in the following format.
## DB_CHANGE_REQUIRED
| 항목 | 내용 |
|------|------|
| 요청 유형 | 컬럼 추가/컬럼 수정/인덱스 추가/상태값 추가 |
| 대상 테이블 | [테이블명] |
| 대상 컬럼 | [컬럼명 또는 신규 컬럼명] |
| 필요한 이유 | [구현 중 막힌 이유] |
| 관련 TEST_ID | [T-001] |
| 영향 레이어 | Backend/Store/UI/E2E |
| 권장 DDL | [가능하면 제안, 확정은 gen-db가 판단] |
Handling criteria:
- If a new table/column/index/status value is needed, generate a migration with this skill or
peach-db-migrate. - If the already generated schema file and the actual DB differ,
peach-db-extract-schemafirst update the current state with - After the DB change,
api/db/schema/...update it, and based on the changed schema,peach-team-devresume.
DB_DECISION_REQUIRED handling
If the DB determination is ambiguous in the Spec or input definition, do not force the migration and report in the following format.
## DB_DECISION_REQUIRED
| 항목 | 내용 |
|------|------|
| 판단 대상 | 테이블/컬럼/인덱스/상태값/이력 테이블 |
| 후보안 | [A안, B안] |
| 모호한 이유 | [Spec/입력 정의에서 확정 불가한 지점] |
| 영향 범위 | Backend/Store/UI/E2E |
| 필요한 결정 | [사용자 또는 기획 확인 사항] |
DB_DECISION_REQUIREDis not subject to the Ralph Loop. After the criteria are confirmed, run this skill again.
Migration generation conditions
Only when one of the following is satisfied, api/db/migrations/... generate the file.
- The input is a confirmed Spec.
- A clear
DB_CHANGE_REQUIREDrequest for the existing schema.
If the conditions are not satisfied, report only the DB/ERD candidates and items requiring decisions, then exit.
Input method
Method 1: Spec document path
Spec 경로: docs/spec/{년}/{월}/{개발자아이디}-260506-공지사항-게시판.md
Method 2: Define table directly
테이블명: notice_board
설명: 공지사항 게시판
컬럼:
- title: VARCHAR(200) NOT NULL - 제목(필수,최대200자)
- content: TEXT - 내용
- status: CHAR(1) DEFAULT 'A' - 상태(A:활성,I:비활성,D:삭제)
Workflow
- Determine DB type:
api/src/environments/env.local.ymlRead and check DATABASE_URL - Input analysis: Parse Spec or table definition
- Spec-based extraction: Extract entity/relationship/status values/history/attachment criteria
- Separate items requiring decision: For DB determinations that cannot be confirmed,
DB_DECISION_REQUIREDreport to and stop migration generation - Type mapping: type-mapping.md Reference (section matching DB type)
- DDL generation: ddl-template.md Use template (section matching DB type)
- Write comments: comment-guide.md Follow guide
- Flow verification: After DDL generation, check the following items
- Whether state transitions are represented without omission (completeness of code values in the status column)
- Whether all columns required at INSERT/UPDATE time are present
- Whether the history table (
*_hist,*_log) is sufficient for audit tracing
- Check whether change requests are reflected: If the input contains
DB_CHANGE_REQUIRED, record the relatedTEST_IDand affected layers in the DDL comments/completion report - Generate migration file: Only when the migration generation conditions are met,
api/db/migrations/[timestamp]_create_[테이블명]_table.sqlgenerate
Reference documents
Check the necessary information for the task in the relevant documents:
- type-mapping.md: PostgreSQL/MySQL type mapping rules
- ddl-template.md: DDL templates and complete examples
- comment-guide.md: Column comment writing guide
Apply migration
After generating the migration file:
# 1. 마이그레이션 적용
cd api && bun run db:up-dev
# 2. 스키마 파일 자동 추출
# → api/db/schema/[도메인]/[테이블명].sql 생성됨
Post-completion guidance
✅ DB 스키마 처리 완료!
DB 종류: [PostgreSQL/MySQL]
원천 자료: [Spec/직접 정의]
생성된 파일:
- DB/ERD 후보: [경로 또는 해당 없음]
- 마이그레이션: api/db/migrations/[timestamp]_create_[테이블명]_table.sql 또는 [보류]
⚠️ FK 제약조건 없음 (의도적)
✅ 컬럼 코멘트 상세 작성 완료
✅ 선택값/상태값 코드화 완료
✅ DB_DECISION_REQUIRED: [없음/있음 - 결정 필요 항목 N개]
✅ DB_CHANGE_REQUIRED 반영 여부: [해당 없음/반영/보류]
다음 단계:
1. 마이그레이션 적용: cd api && bun run db:up-dev
2. 스키마 확인: cat api/db/schema/[도메인]/[테이블].sql
3. 플로우 검증 완료 여부 확인
Additional references
- Existing migrations:
api/db/migrations/ - Schema extraction:
api/db/scripts/extract-schema.ts - Schema file:
api/db/schema/[도메인]/[테이블].sql