| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- // EKS Support Relay — persistence layer.
- // SQLite for now; the schema deliberately avoids SQLite-only features so a
- // later move to PostgreSQL only needs a datasource/provider change.
- generator client {
- provider = "prisma-client-js"
- output = "../node_modules/.prisma/client"
- }
- datasource db {
- provider = "sqlite"
- url = env("DATABASE_URL")
- }
- /// One row per inbound source message. Primary idempotency guard for the
- /// Chatwoot webhook: (source, messageId) is unique.
- model ProcessedMessage {
- id String @id @default(cuid())
- source String
- messageId String
- conversationId Int
- /// queued | processing | replied | skipped | ticket | failed | spam
- status String
- reason String?
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
- @@unique([source, messageId])
- @@index([conversationId])
- @@index([status])
- }
- /// Async work item. The webhook persists a job and returns 202; the in-process
- /// worker picks it up, with retries and exponential backoff.
- model Job {
- id String @id @default(cuid())
- /// chatwoot_message
- type String
- /// queued | processing | done | failed | dead
- status String @default("queued")
- attempts Int @default(0)
- maxAttempts Int @default(3)
- /// Redacted, minimal payload — never full secrets.
- payloadJson String
- /// Redacted error text.
- lastError String?
- runAfter DateTime @default(now())
- startedAt DateTime?
- finishedAt DateTime?
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
- @@index([status, runAfter])
- }
- /// Handoff record. conversationId is unique so repeated new_ticket calls for
- /// the same conversation always resolve to the same ticket number.
- model Ticket {
- id String @id @default(cuid())
- conversationId Int @unique
- ticketNumber String
- reason String?
- createdAt DateTime @default(now())
- }
- /// Non-secret audit trail of decisions taken per message/conversation.
- model AuditEvent {
- id String @id @default(cuid())
- conversationId Int?
- messageId String?
- eventType String
- summary String
- /// Redacted JSON metadata.
- metaJson String?
- createdAt DateTime @default(now())
- @@index([conversationId])
- @@index([eventType])
- @@index([createdAt])
- }
|