본문으로 건너뛰기

데이터 모델/스키마

이 문서로 해결할 질문

  • PostgreSQL vs MongoDB에 무엇이 저장되나요?
  • Prisma·Mongoose 스키마의 코드 기준은 어디인가요?

저장소 분리

저장소ORM주요 모델
PostgreSQLPrismaUser, Recipe, Ingredient, RecipeEmbedding, UserRecipeRecommendation, ChatbotCreditDeduction
MongoDBMongooseInventory, ChatbotLog, ChatbotConversation, EventLog, recipe_ingestion_*, kpi_rollups

엔티티 의미와 필드 설명은 도메인 문서를 참고하세요.

PostgreSQL (Prisma)

Prisma 스키마의 코드 기준은 server/shared/.../schema.prisma입니다.

모델핵심 필드·관계
Useremail, platformName/Id, creditBalance
RecipeCategorykey, name, displayOrder
Recipeinstructions(JSON), nutrition(JSON), categoryId
RecipeStatsviewCount, likeCount (1:1 Recipe)
IngredientCategorykey, name, displayOrder
Ingredientname, categoryId
RecipeIngredientrecipeId, ingredientId, amount
RecipeEmbeddingrecipeId PK, embedding(vector), documentText, version
UserRecipeRecommendationuserId, recipeId, rank, score, reason
ChatbotCreditDeductionstreamChannelId 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
inventoryinventory.schema.ts
chatbot_logschatbot-log.schema.ts30일
chatbot_conversationschatbot-conversation.schema.ts
event_logsevent-log.schema.ts90일
recipe_ingestion_jobsrecipe-ingestion-job.schema.ts
recipe_ingestion_staterecipe-ingestion-state.schema.ts
kpi_rollupskpi-rollup.schema.ts400일

시드·인덱스

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

변경 체크리스트

  1. schema.prisma 또는 Mongoose 스키마를 수정합니다.
  2. PostgreSQL 마이그레이션을 생성·적용하고, Mongoose 인덱스를 동기화합니다.
  3. 도메인 문서와 본 문서를 갱신합니다.
  4. OpenAPI DTO와 관련 문서를 동기화합니다.
  5. Docusaurus의 본 문서와 도메인 문서를 갱신합니다.

관련 문서