mirror of
https://github.com/ZeroCatDev/ClassworksKV.git
synced 2025-10-22 18:33:11 +00:00
71 lines
2.2 KiB
Plaintext
71 lines
2.2 KiB
Plaintext
generator client {
|
||
provider = "prisma-client-js"
|
||
}
|
||
|
||
datasource db {
|
||
provider = "mysql"
|
||
url = env("DATABASE_URL")
|
||
}
|
||
|
||
model KVStore {
|
||
deviceId Int // 设备ID,作为namespace的一部分
|
||
key String
|
||
value Json
|
||
creatorIp String? @default("")
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
// 关联关系
|
||
device Device @relation(fields: [deviceId], references: [id], onDelete: Cascade)
|
||
|
||
@@id([deviceId, key])
|
||
}
|
||
|
||
model Account {
|
||
id String @id @default(cuid())
|
||
provider String // OAuth提供者 (例如: google, github, gitlab等)
|
||
providerId String // 提供者返回的用户唯一ID
|
||
email String? // 用户邮箱
|
||
name String? // 用户名称
|
||
avatarUrl String? // 用户头像URL
|
||
providerData Json? // OAuth提供者返回的完整信息
|
||
accessToken String @unique // 账户访问令牌
|
||
refreshToken String? // OAuth refresh token (如果提供者支持)
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
// 关联的设备
|
||
devices Device[]
|
||
|
||
@@unique([provider, providerId]) // 确保同一提供者的用户ID唯一
|
||
}
|
||
|
||
model Device {
|
||
id Int @id @default(autoincrement())
|
||
uuid String @unique // 设备的唯一标识符
|
||
name String?
|
||
accountId String? // 关联的账户ID
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
password String?
|
||
passwordHint String?
|
||
|
||
// 关联关系
|
||
account Account? @relation(fields: [accountId], references: [id], onDelete: SetNull)
|
||
appInstalls AppInstall[]
|
||
kvStore KVStore[] // 设备相关的KV存储
|
||
}
|
||
|
||
model AppInstall {
|
||
id String @id @default(cuid())
|
||
deviceId Int // 关联的设备ID
|
||
appId String // 应用ID (SHA256 hash)
|
||
token String @unique // 应用安装的唯一访问令牌,拥有完整KV读写权限
|
||
note String? // 安装备注
|
||
installedAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
// 关联关系
|
||
device Device @relation(fields: [deviceId], references: [id], onDelete: Cascade)
|
||
}
|