162 lines
4.4 KiB
Plaintext
162 lines
4.4 KiB
Plaintext
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
}
|
|
|
|
enum MessageDirection {
|
|
ELDER_TO_FAMILY
|
|
FAMILY_TO_ELDER
|
|
}
|
|
|
|
enum MessageImportance {
|
|
LOW
|
|
NORMAL
|
|
HIGH
|
|
URGENT
|
|
}
|
|
|
|
enum MessageStatus {
|
|
PENDING
|
|
DELIVERED
|
|
READ
|
|
}
|
|
|
|
enum ConversationRole {
|
|
USER
|
|
ASSISTANT
|
|
TOOL
|
|
}
|
|
|
|
enum UsageEventType {
|
|
APP_OPEN
|
|
SETTINGS_OPENED
|
|
AI_SESSION_STARTED
|
|
AI_SESSION_ENDED
|
|
CAMERA_ENABLED
|
|
CAMERA_DISABLED
|
|
TOOL_CALLED
|
|
}
|
|
|
|
enum ToolCallStatus {
|
|
SUCCESS
|
|
FAILURE
|
|
}
|
|
|
|
model CaregiverAccount {
|
|
id String @id @default(cuid())
|
|
sessionToken String @unique
|
|
nickname String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
bindings DeviceBinding[]
|
|
messages FamilyMessage[]
|
|
pushSubscriptions PushSubscription[]
|
|
}
|
|
|
|
model ElderDevice {
|
|
id String @id @default(cuid())
|
|
deviceUuid String @unique
|
|
displayName String?
|
|
appVersion String?
|
|
lastSeenAt DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
bindings DeviceBinding[]
|
|
messages FamilyMessage[]
|
|
conversationTurns ConversationTurn[]
|
|
usageEvents UsageEvent[]
|
|
toolCalls ToolCallLog[]
|
|
}
|
|
|
|
model DeviceBinding {
|
|
id String @id @default(cuid())
|
|
caregiverId String
|
|
elderDeviceId String
|
|
createdAt DateTime @default(now())
|
|
caregiver CaregiverAccount @relation(fields: [caregiverId], references: [id], onDelete: Cascade)
|
|
elderDevice ElderDevice @relation(fields: [elderDeviceId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([caregiverId, elderDeviceId])
|
|
@@index([elderDeviceId, createdAt])
|
|
}
|
|
|
|
model FamilyMessage {
|
|
id String @id @default(cuid())
|
|
publicId Int @unique @default(autoincrement())
|
|
elderDeviceId String
|
|
caregiverId String?
|
|
direction MessageDirection
|
|
content String
|
|
recipientRelation String?
|
|
importance MessageImportance @default(NORMAL)
|
|
status MessageStatus @default(PENDING)
|
|
source String?
|
|
createdAt DateTime @default(now())
|
|
deliveredAt DateTime?
|
|
readAt DateTime?
|
|
elderDevice ElderDevice @relation(fields: [elderDeviceId], references: [id], onDelete: Cascade)
|
|
caregiver CaregiverAccount? @relation(fields: [caregiverId], references: [id], onDelete: SetNull)
|
|
|
|
@@index([elderDeviceId, createdAt(sort: Desc)])
|
|
@@index([direction, status, createdAt(sort: Desc)])
|
|
}
|
|
|
|
model PushSubscription {
|
|
id String @id @default(cuid())
|
|
caregiverId String
|
|
endpoint String @unique
|
|
p256dh String
|
|
auth String
|
|
expirationTime DateTime?
|
|
userAgent String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
caregiver CaregiverAccount @relation(fields: [caregiverId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([caregiverId, updatedAt(sort: Desc)])
|
|
}
|
|
|
|
model ConversationTurn {
|
|
id String @id @default(cuid())
|
|
elderDeviceId String
|
|
sessionId String?
|
|
role ConversationRole
|
|
content String
|
|
metaJson String?
|
|
createdAt DateTime @default(now())
|
|
elderDevice ElderDevice @relation(fields: [elderDeviceId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([elderDeviceId, createdAt(sort: Desc)])
|
|
@@index([sessionId, createdAt])
|
|
}
|
|
|
|
model UsageEvent {
|
|
id String @id @default(cuid())
|
|
elderDeviceId String
|
|
eventType UsageEventType
|
|
detailJson String?
|
|
createdAt DateTime @default(now())
|
|
elderDevice ElderDevice @relation(fields: [elderDeviceId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([elderDeviceId, createdAt(sort: Desc)])
|
|
@@index([eventType, createdAt(sort: Desc)])
|
|
}
|
|
|
|
model ToolCallLog {
|
|
id String @id @default(cuid())
|
|
elderDeviceId String
|
|
sessionId String?
|
|
callId String?
|
|
toolName String
|
|
argumentsJson String
|
|
outputText String?
|
|
status ToolCallStatus
|
|
createdAt DateTime @default(now())
|
|
elderDevice ElderDevice @relation(fields: [elderDeviceId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([elderDeviceId, createdAt(sort: Desc)])
|
|
@@index([toolName, createdAt(sort: Desc)])
|
|
} |