ai.prisma 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. model AiGeneratedMessage {
  2. id String @id @default(cuid())
  3. vehicleId String
  4. type String // "summary" | "common_issues" | etc.
  5. content String
  6. createdAt DateTime @default(now())
  7. updatedAt DateTime @updatedAt
  8. vehicle Vehicle @relation(fields: [vehicleId], references: [id], onDelete: Cascade)
  9. @@unique([vehicleId, type])
  10. @@map("ai_generated_messages")
  11. }
  12. /// A conversation about one vehicle or one customer. The chat is scoped to
  13. /// that record on purpose: the model is handed the record's own data and
  14. /// nothing else, so it can only ever talk about what the page it was opened
  15. /// from already shows. Exactly one of vehicleId and customerId is set.
  16. model AiChat {
  17. id String @id @default(cuid())
  18. title String @default("New chat")
  19. createdAt DateTime @default(now())
  20. updatedAt DateTime @updatedAt
  21. userId String
  22. organizationId String
  23. vehicleId String?
  24. vehicle Vehicle? @relation(fields: [vehicleId], references: [id], onDelete: Cascade)
  25. customerId String?
  26. customer Customer? @relation(fields: [customerId], references: [id], onDelete: Cascade)
  27. messages AiChatMessage[]
  28. @@index([organizationId, userId, updatedAt(sort: Desc)])
  29. @@index([vehicleId])
  30. @@index([customerId])
  31. @@map("ai_chats")
  32. }
  33. model AiChatMessage {
  34. id String @id @default(cuid())
  35. role String // "user" | "assistant"
  36. content String
  37. createdAt DateTime @default(now())
  38. chatId String
  39. chat AiChat @relation(fields: [chatId], references: [id], onDelete: Cascade)
  40. @@index([chatId, createdAt])
  41. @@map("ai_chat_messages")
  42. }