feat(api-db): add task attachment and sync models
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
// Get a free hosted Postgres database in seconds: `npx create-db`
|
||||
// Prisma 数据模型定义(TodoList)
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client"
|
||||
@@ -25,6 +22,27 @@ enum AuthProvider {
|
||||
WECHAT
|
||||
}
|
||||
|
||||
enum TaskPriority {
|
||||
LOW
|
||||
MEDIUM
|
||||
HIGH
|
||||
URGENT
|
||||
}
|
||||
|
||||
enum TaskStatus {
|
||||
TODO
|
||||
IN_PROGRESS
|
||||
DONE
|
||||
ARCHIVED
|
||||
}
|
||||
|
||||
enum AttachmentType {
|
||||
IMAGE
|
||||
VIDEO
|
||||
FILE
|
||||
LINK
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
email String @unique
|
||||
@@ -38,6 +56,13 @@ model User {
|
||||
identities AuthIdentity[]
|
||||
refreshTokens RefreshToken[]
|
||||
security UserSecurity?
|
||||
tasks Task[]
|
||||
tags Tag[]
|
||||
attachments Attachment[]
|
||||
taskActivityLogs TaskActivityLog[]
|
||||
syncOperations SyncOperation[]
|
||||
syncCursors SyncCursor[]
|
||||
taskTombstones TaskTombstone[]
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
@@ -83,3 +108,135 @@ model RefreshToken {
|
||||
@@index([userId, expiresAt])
|
||||
@@map("refresh_tokens")
|
||||
}
|
||||
|
||||
model Task {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
title String
|
||||
contentJson Json?
|
||||
contentText String?
|
||||
priority TaskPriority @default(MEDIUM)
|
||||
status TaskStatus @default(TODO)
|
||||
ddl DateTime?
|
||||
completedAt DateTime?
|
||||
version Int @default(1)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
taskTags TaskTag[]
|
||||
attachments Attachment[]
|
||||
activityLogs TaskActivityLog[]
|
||||
|
||||
@@index([userId, status])
|
||||
@@index([userId, ddl])
|
||||
@@map("tasks")
|
||||
}
|
||||
|
||||
model Tag {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
name String
|
||||
color String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
taskTags TaskTag[]
|
||||
|
||||
@@unique([userId, name])
|
||||
@@index([userId])
|
||||
@@map("tags")
|
||||
}
|
||||
|
||||
model TaskTag {
|
||||
taskId String
|
||||
tagId String
|
||||
createdAt DateTime @default(now())
|
||||
task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
|
||||
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([taskId, tagId])
|
||||
@@index([tagId])
|
||||
@@map("task_tags")
|
||||
}
|
||||
|
||||
model Attachment {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
taskId String?
|
||||
type AttachmentType
|
||||
url String
|
||||
mimeType String?
|
||||
fileName String?
|
||||
fileSize Int
|
||||
width Int?
|
||||
height Int?
|
||||
durationMs Int?
|
||||
checksum String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
task Task? @relation(fields: [taskId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([userId])
|
||||
@@index([taskId])
|
||||
@@map("attachments")
|
||||
}
|
||||
|
||||
model TaskActivityLog {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
taskId String
|
||||
action String
|
||||
payload Json?
|
||||
createdAt DateTime @default(now())
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([taskId, createdAt])
|
||||
@@index([userId, createdAt])
|
||||
@@map("task_activity_logs")
|
||||
}
|
||||
|
||||
model SyncOperation {
|
||||
id String @id @default(cuid())
|
||||
opId String @unique
|
||||
userId String
|
||||
deviceId String
|
||||
entityType String
|
||||
entityId String
|
||||
action String
|
||||
payload Json?
|
||||
clientTs DateTime
|
||||
serverTs DateTime @default(now())
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId, deviceId, serverTs])
|
||||
@@index([userId, entityType, entityId])
|
||||
@@map("sync_operations")
|
||||
}
|
||||
|
||||
model SyncCursor {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
deviceId String
|
||||
lastPulledAt DateTime?
|
||||
lastOperationServerTs DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([userId, deviceId])
|
||||
@@map("sync_cursors")
|
||||
}
|
||||
|
||||
model TaskTombstone {
|
||||
id String @id @default(cuid())
|
||||
taskId String @unique
|
||||
userId String
|
||||
deletedAt DateTime @default(now())
|
||||
deleteOpId String?
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId, deletedAt])
|
||||
@@map("task_tombstones")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user