데이터 모델/스키마
이 문서로 해결할 질문
- PostgreSQL vs MongoDB에 무엇이 저장되나요?
- Prisma·Mongoose 스키마의 코드 기준은 어디인가요?
저장소 분리
| 저장소 | ORM | 주요 모델 |
|---|---|---|
| PostgreSQL | Prisma | User, Recipe, Ingredient, RecipeEmbedding, UserRecipeRecommendation, ChatbotCreditDeduction |
| MongoDB | Mongoose | Inventory, ChatbotLog, ChatbotConversation, EventLog, recipe_ingestion_*, kpi_rollups |
엔티티 의미와 필드 설명은 도메인 문서를 참고하세요.
PostgreSQL (Prisma)
Prisma 스키마의 코드 기준은 server/shared/.../schema.prisma입니다.
| 모델 | 핵심 필드·관계 |
|---|---|
| User | email, platformName/Id, creditBalance |
| RecipeCategory | key, name, displayOrder |
| Recipe | instructions(JSON), nutrition(JSON), categoryId |
| RecipeStats | viewCount, likeCount (1:1 Recipe) |
| IngredientCategory | key, name, displayOrder |
| Ingredient | name, categoryId |
| RecipeIngredient | recipeId, ingredientId, amount |
| RecipeEmbedding | recipeId PK, embedding(vector), documentText, version |
| UserRecipeRecommendation | userId, recipeId, rank, score, reason |
| ChatbotCreditDeduction | streamChannelId PK, credits |
마이그레이션 파일은 server/shared/.../migrations/에 있습니다.
pnpm run db:prisma:migrate:dev
pnpm run db:prisma:migrate:deploy # prod
MongoDB (Mongoose)
Mongoose 스키마의 코드 기준은 server/shared/.../schemas/입니다.
| 컬렉션 | 스키마 파일 | TTL |
|---|---|---|
inventory | inventory.schema.ts | — |
chatbot_logs | chatbot-log.schema.ts | 30일 |
chatbot_conversations | chatbot-conversation.schema.ts | — |
event_logs | event-log.schema.ts | 90일 |
recipe_ingestion_jobs | recipe-ingestion-job.schema.ts | — |
recipe_ingestion_state | recipe-ingestion-state.schema.ts | — |
kpi_rollups | kpi-rollup.schema.ts | 400일 |
시드·인덱스
pnpm run db:prisma:seed
pnpm run db:mongoose:seed
pnpm run db:mongoose:sync-indexes # local
pnpm run db:mongoose:sync-indexes:production # production
변경 체크리스트
schema.prisma또는 Mongoose 스키마를 수정합니다.- PostgreSQL 마이그레이션을 생성·적용하고, Mongoose 인덱스를 동기화합니다.
- 도메인 문서와 본 문서를 갱신합니다.
- OpenAPI DTO와 관련 문서를 동기화합니다.
- Docusaurus의 본 문서와 도메인 문서를 갱신합니다.