230 lines
6.8 KiB
Plaintext
230 lines
6.8 KiB
Plaintext
generator client {
|
|
provider = "prisma-client-js"
|
|
binaryTargets = ["native", "linux-musl", "debian-openssl-3.0.x"]
|
|
output = "../node_modules/.prisma/project-client"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
// 客户表
|
|
model Customer {
|
|
id String @id @default(uuid())
|
|
companyName String @map("company_name")
|
|
contactName String? @map("contact_name")
|
|
contactEmail String? @map("contact_email")
|
|
contactPhone String? @map("contact_phone")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
licenses License[]
|
|
|
|
@@map("customers")
|
|
}
|
|
|
|
// 许可证类型枚举
|
|
enum LicenseType {
|
|
FREE
|
|
STANDARD
|
|
PRO
|
|
}
|
|
|
|
// 许可证状态枚举
|
|
enum LicenseStatus {
|
|
active
|
|
disabled
|
|
expired
|
|
}
|
|
|
|
enum ModuleGrantStatus {
|
|
active
|
|
disabled
|
|
revoked
|
|
}
|
|
|
|
// 许可证表
|
|
model License {
|
|
id String @id @default(uuid())
|
|
customerId String? @map("customer_id")
|
|
licenseKey String @unique @map("license_key")
|
|
licenseType LicenseType @map("license_type")
|
|
customerName String? @map("customer_name") // 客户名称(免费版注册时填写)
|
|
contactInfo String? @map("contact_info") // 联系方式(手机/微信/邮箱)
|
|
status LicenseStatus @default(active)
|
|
maxUsers Int @default(-1) @map("max_users")
|
|
maxMaterials Int @default(-1) @map("max_materials")
|
|
features Json @default("{}")
|
|
expiresAt DateTime? @map("expires_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
customer Customer? @relation(fields: [customerId], references: [id])
|
|
activations Activation[]
|
|
heartbeatLogs HeartbeatLog[]
|
|
alerts Alert[]
|
|
order Order?
|
|
moduleGrants LicenseModuleGrant[]
|
|
pullTokenAudits ModulePullTokenAudit[]
|
|
|
|
@@map("licenses")
|
|
}
|
|
|
|
model LicenseModuleGrant {
|
|
id String @id @default(uuid())
|
|
licenseId String @map("license_id")
|
|
moduleId String @map("module_id")
|
|
status ModuleGrantStatus @default(active)
|
|
image String?
|
|
version String?
|
|
digest String?
|
|
expiresAt DateTime? @map("expires_at")
|
|
revokedAt DateTime? @map("revoked_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
license License @relation(fields: [licenseId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([licenseId, moduleId])
|
|
@@index([licenseId, status])
|
|
@@index([moduleId, status])
|
|
@@map("license_module_grants")
|
|
}
|
|
|
|
model ModulePullTokenAudit {
|
|
id String @id @default(uuid())
|
|
licenseId String @map("license_id")
|
|
activationId String? @map("activation_id")
|
|
moduleId String @map("module_id")
|
|
repository String
|
|
digest String?
|
|
tokenHash String @map("token_hash")
|
|
expiresAt DateTime @map("expires_at")
|
|
lastValidatedAt DateTime? @map("last_validated_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
license License @relation(fields: [licenseId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([licenseId, moduleId])
|
|
@@index([tokenHash])
|
|
@@index([expiresAt])
|
|
@@map("module_pull_token_audits")
|
|
}
|
|
|
|
// 激活记录表
|
|
model Activation {
|
|
id String @id @default(uuid())
|
|
licenseId String @map("license_id")
|
|
instanceId String @map("instance_id")
|
|
fingerprint Json
|
|
activatedAt DateTime @default(now()) @map("activated_at")
|
|
lastHeartbeat DateTime? @map("last_heartbeat")
|
|
usageStats Json @default("{}") @map("usage_stats")
|
|
isActive Boolean @default(true) @map("is_active")
|
|
|
|
license License @relation(fields: [licenseId], references: [id])
|
|
|
|
@@map("activations")
|
|
}
|
|
|
|
// 心跳记录表
|
|
model HeartbeatLog {
|
|
id String @id @default(uuid())
|
|
licenseId String @map("license_id")
|
|
instanceId String @map("instance_id")
|
|
fingerprintHash String @map("fingerprint_hash")
|
|
ipAddress String? @map("ip_address")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
license License @relation(fields: [licenseId], references: [id])
|
|
|
|
@@map("heartbeat_logs")
|
|
}
|
|
|
|
// 告警类型枚举
|
|
enum AlertStatus {
|
|
pending
|
|
resolved
|
|
ignored
|
|
}
|
|
|
|
// 告警表
|
|
model Alert {
|
|
id String @id @default(uuid())
|
|
licenseId String @map("license_id")
|
|
alertType String @map("alert_type")
|
|
details Json?
|
|
status AlertStatus @default(pending)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
resolvedAt DateTime? @map("resolved_at")
|
|
|
|
license License @relation(fields: [licenseId], references: [id])
|
|
|
|
@@map("alerts")
|
|
}
|
|
|
|
// 管理员表
|
|
model Admin {
|
|
id String @id @default(uuid())
|
|
username String @unique
|
|
passwordHash String @map("password_hash")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@map("admins")
|
|
}
|
|
|
|
// 订单记录表(官网购买记录)
|
|
model Order {
|
|
id String @id @default(uuid())
|
|
orderNo String @unique @map("order_no")
|
|
plan LicenseType
|
|
customerEmail String @map("customer_email")
|
|
customerName String? @map("customer_name")
|
|
licenseId String? @unique @map("license_id")
|
|
validDays Int @default(365) @map("valid_days")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
license License? @relation(fields: [licenseId], references: [id])
|
|
|
|
@@map("orders")
|
|
}
|
|
|
|
// API 密钥表(官网调用认证)
|
|
model ApiKey {
|
|
id String @id @default(uuid())
|
|
name String
|
|
keyHash String @unique @map("key_hash")
|
|
isActive Boolean @default(true) @map("is_active")
|
|
lastUsedAt DateTime? @map("last_used_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
@@map("api_keys")
|
|
}
|
|
|
|
// 版本信息表(素材系统)
|
|
model Version {
|
|
id String @id @default(uuid())
|
|
version String @unique
|
|
releaseNotes String? @map("release_notes")
|
|
minRequiredVersion String? @map("min_required_version")
|
|
isSecurityUpdate Boolean @default(false) @map("is_security_update")
|
|
isCriticalUpdate Boolean @default(false) @map("is_critical_update")
|
|
downloadSize String? @map("download_size")
|
|
releaseDate DateTime @default(now()) @map("release_date")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
@@map("versions")
|
|
}
|
|
|
|
// Agent 版本信息表
|
|
model AgentVersion {
|
|
id String @id @default(uuid())
|
|
version String @unique
|
|
releaseNotes String? @map("release_notes")
|
|
releaseDate DateTime @default(now()) @map("release_date")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
@@map("agent_versions")
|
|
}
|