2024-09-03 20:19:33 +08:00
|
|
|
|
// This is your Prisma schema file,
|
|
|
|
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
|
|
|
|
|
|
|
|
generator client {
|
2024-12-30 08:26:40 +08:00
|
|
|
|
provider = "prisma-client-js"
|
2024-09-03 20:19:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
datasource db {
|
2024-12-30 08:26:40 +08:00
|
|
|
|
provider = "postgresql"
|
|
|
|
|
url = env("DATABASE_URL")
|
2024-09-03 20:19:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Taxonomy {
|
2024-12-30 13:44:30 +08:00
|
|
|
|
id String @id @default(cuid())
|
2024-12-30 08:26:40 +08:00
|
|
|
|
name String @unique
|
|
|
|
|
slug String @unique @map("slug")
|
|
|
|
|
deletedAt DateTime? @map("deleted_at")
|
|
|
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
|
terms Term[]
|
|
|
|
|
objectType String[] @map("object_type")
|
|
|
|
|
order Float? @map("order")
|
2024-09-03 20:19:33 +08:00
|
|
|
|
|
2024-12-30 08:26:40 +08:00
|
|
|
|
@@index([order, deletedAt])
|
|
|
|
|
@@map("taxonomy")
|
2024-09-03 20:19:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Term {
|
2024-12-30 13:44:30 +08:00
|
|
|
|
id String @id @default(cuid())
|
2024-12-30 08:26:40 +08:00
|
|
|
|
name String
|
|
|
|
|
taxonomy Taxonomy? @relation(fields: [taxonomyId], references: [id])
|
|
|
|
|
taxonomyId String? @map("taxonomy_id")
|
|
|
|
|
order Float? @map("order")
|
|
|
|
|
description String?
|
|
|
|
|
parentId String? @map("parent_id")
|
|
|
|
|
parent Term? @relation("ChildParent", fields: [parentId], references: [id], onDelete: Cascade)
|
|
|
|
|
children Term[] @relation("ChildParent")
|
|
|
|
|
ancestors TermAncestry[] @relation("DescendantToAncestor")
|
|
|
|
|
descendants TermAncestry[] @relation("AncestorToDescendant")
|
|
|
|
|
domainId String? @map("domain_id")
|
|
|
|
|
domain Department? @relation("TermDom", fields: [domainId], references: [id])
|
|
|
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
|
deletedAt DateTime? @map("deleted_at")
|
|
|
|
|
createdBy String? @map("created_by")
|
|
|
|
|
depts Department[] @relation("department_term")
|
|
|
|
|
hasChildren Boolean? @default(false) @map("has_children")
|
2025-02-21 13:20:15 +08:00
|
|
|
|
|
2024-12-30 08:26:40 +08:00
|
|
|
|
@@index([name]) // 对name字段建立索引,以加快基于name的查找速度
|
|
|
|
|
@@index([parentId]) // 对parentId字段建立索引,以加快基于parentId的查找速度
|
|
|
|
|
@@map("term")
|
2024-09-03 20:19:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model TermAncestry {
|
2024-12-30 13:44:30 +08:00
|
|
|
|
id String @id @default(cuid())
|
2024-12-30 08:26:40 +08:00
|
|
|
|
ancestorId String? @map("ancestor_id")
|
|
|
|
|
descendantId String @map("descendant_id")
|
|
|
|
|
relDepth Int @map("rel_depth")
|
|
|
|
|
ancestor Term? @relation("AncestorToDescendant", fields: [ancestorId], references: [id])
|
|
|
|
|
descendant Term @relation("DescendantToAncestor", fields: [descendantId], references: [id])
|
2024-09-03 20:19:33 +08:00
|
|
|
|
|
2024-12-30 08:26:40 +08:00
|
|
|
|
// 索引建议
|
|
|
|
|
@@index([ancestorId]) // 针对祖先的查询
|
|
|
|
|
@@index([descendantId]) // 针对后代的查询
|
|
|
|
|
@@index([ancestorId, descendantId]) // 组合索引,用于查询特定的祖先-后代关系
|
|
|
|
|
@@index([relDepth]) // 根据关系深度的查询
|
|
|
|
|
@@map("term_ancestry")
|
2024-09-03 20:19:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Staff {
|
2024-12-30 13:44:30 +08:00
|
|
|
|
id String @id @default(cuid())
|
2024-12-30 08:26:40 +08:00
|
|
|
|
showname String? @map("showname")
|
|
|
|
|
username String @unique @map("username")
|
|
|
|
|
avatar String? @map("avatar")
|
|
|
|
|
password String? @map("password")
|
|
|
|
|
phoneNumber String? @unique @map("phone_number")
|
|
|
|
|
|
|
|
|
|
domainId String? @map("domain_id")
|
|
|
|
|
deptId String? @map("dept_id")
|
|
|
|
|
|
2024-12-30 13:44:30 +08:00
|
|
|
|
domain Department? @relation("DomainStaff", fields: [domainId], references: [id])
|
|
|
|
|
department Department? @relation("DeptStaff", fields: [deptId], references: [id])
|
|
|
|
|
order Float?
|
2024-09-03 20:19:33 +08:00
|
|
|
|
|
2024-12-30 08:26:40 +08:00
|
|
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
|
enabled Boolean? @default(true)
|
|
|
|
|
deletedAt DateTime? @map("deleted_at")
|
|
|
|
|
officerId String? @map("officer_id")
|
2024-09-03 20:19:33 +08:00
|
|
|
|
|
2024-12-31 15:57:32 +08:00
|
|
|
|
registerToken String?
|
2025-01-03 09:24:46 +08:00
|
|
|
|
ownedResources Resource[]
|
2024-12-30 08:26:40 +08:00
|
|
|
|
|
|
|
|
|
@@index([officerId])
|
|
|
|
|
@@index([deptId])
|
|
|
|
|
@@index([domainId])
|
|
|
|
|
@@index([username])
|
|
|
|
|
@@index([order])
|
|
|
|
|
@@map("staff")
|
2024-09-03 20:19:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Department {
|
2024-12-30 13:44:30 +08:00
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
name String
|
|
|
|
|
order Float?
|
2025-05-20 10:29:13 +08:00
|
|
|
|
deptDevices Device[] @relation("DeptDevice")
|
2024-12-30 13:44:30 +08:00
|
|
|
|
ancestors DeptAncestry[] @relation("DescendantToAncestor")
|
|
|
|
|
descendants DeptAncestry[] @relation("AncestorToDescendant")
|
|
|
|
|
parentId String? @map("parent_id")
|
|
|
|
|
parent Department? @relation("ChildParent", fields: [parentId], references: [id])
|
|
|
|
|
children Department[] @relation("ChildParent")
|
|
|
|
|
domainId String? @map("domain_id")
|
|
|
|
|
domainTerms Term[] @relation("TermDom")
|
|
|
|
|
deletedAt DateTime? @map("deleted_at")
|
|
|
|
|
isDomain Boolean? @default(false) @map("is_domain")
|
|
|
|
|
domainStaffs Staff[] @relation("DomainStaff")
|
|
|
|
|
deptStaffs Staff[] @relation("DeptStaff")
|
|
|
|
|
terms Term[] @relation("department_term")
|
|
|
|
|
|
2025-02-26 21:08:38 +08:00
|
|
|
|
// watchedPost Post[] @relation("post_watch_dept")
|
2024-12-30 13:44:30 +08:00
|
|
|
|
hasChildren Boolean? @default(false) @map("has_children")
|
2024-12-30 08:26:40 +08:00
|
|
|
|
|
|
|
|
|
@@index([parentId])
|
|
|
|
|
@@index([isDomain])
|
|
|
|
|
@@index([name])
|
|
|
|
|
@@index([order])
|
|
|
|
|
@@map("department")
|
2024-09-03 20:19:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model DeptAncestry {
|
2024-12-30 13:44:30 +08:00
|
|
|
|
id String @id @default(cuid())
|
2024-12-30 08:26:40 +08:00
|
|
|
|
ancestorId String? @map("ancestor_id")
|
|
|
|
|
descendantId String @map("descendant_id")
|
|
|
|
|
relDepth Int @map("rel_depth")
|
|
|
|
|
ancestor Department? @relation("AncestorToDescendant", fields: [ancestorId], references: [id])
|
|
|
|
|
descendant Department @relation("DescendantToAncestor", fields: [descendantId], references: [id])
|
|
|
|
|
|
|
|
|
|
// 索引建议
|
|
|
|
|
@@index([ancestorId]) // 针对祖先的查询
|
|
|
|
|
@@index([descendantId]) // 针对后代的查询
|
|
|
|
|
@@index([ancestorId, descendantId]) // 组合索引,用于查询特定的祖先-后代关系
|
|
|
|
|
@@index([relDepth]) // 根据关系深度的查询
|
|
|
|
|
@@map("dept_ancestry")
|
2024-09-03 20:19:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model RoleMap {
|
2024-12-30 13:44:30 +08:00
|
|
|
|
id String @id @default(cuid())
|
2024-12-30 08:26:40 +08:00
|
|
|
|
objectId String @map("object_id")
|
|
|
|
|
roleId String @map("role_id")
|
|
|
|
|
domainId String? @map("domain_id")
|
|
|
|
|
objectType String @map("object_type")
|
|
|
|
|
role Role @relation(fields: [roleId], references: [id])
|
|
|
|
|
|
|
|
|
|
@@index([domainId])
|
|
|
|
|
@@index([objectId])
|
|
|
|
|
@@map("rolemap")
|
2024-09-03 20:19:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model Role {
|
2024-12-30 13:44:30 +08:00
|
|
|
|
id String @id @default(cuid())
|
2024-12-30 08:26:40 +08:00
|
|
|
|
name String @unique @map("name")
|
|
|
|
|
permissions String[] @default([]) @map("permissions")
|
|
|
|
|
roleMaps RoleMap[]
|
|
|
|
|
system Boolean? @default(false) @map("system")
|
|
|
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
|
deletedAt DateTime? @map("deleted_at")
|
|
|
|
|
|
|
|
|
|
@@map("role")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model AppConfig {
|
2024-12-30 13:44:30 +08:00
|
|
|
|
id String @id @default(cuid())
|
2024-12-30 08:26:40 +08:00
|
|
|
|
slug String @unique
|
|
|
|
|
title String?
|
|
|
|
|
description String?
|
|
|
|
|
meta Json?
|
|
|
|
|
|
|
|
|
|
@@map("app_config")
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-30 13:44:30 +08:00
|
|
|
|
model Resource {
|
2025-05-27 10:27:56 +08:00
|
|
|
|
id String @id @default(cuid()) @map("id")
|
|
|
|
|
title String? @map("title")
|
|
|
|
|
description String? @map("description")
|
|
|
|
|
type String? @map("type")
|
|
|
|
|
fileId String? @unique
|
2025-01-06 18:30:16 +08:00
|
|
|
|
url String?
|
2025-01-03 09:24:46 +08:00
|
|
|
|
// 元数据
|
2025-05-27 10:27:56 +08:00
|
|
|
|
meta Json? @map("meta")
|
2025-01-03 09:24:46 +08:00
|
|
|
|
// 处理状态控制
|
2025-01-06 18:30:16 +08:00
|
|
|
|
status String?
|
2025-05-27 10:27:56 +08:00
|
|
|
|
createdAt DateTime? @default(now()) @map("created_at")
|
|
|
|
|
updatedAt DateTime? @updatedAt @map("updated_at")
|
|
|
|
|
createdBy String? @map("created_by")
|
|
|
|
|
updatedBy String? @map("updated_by")
|
|
|
|
|
deletedAt DateTime? @map("deleted_at")
|
|
|
|
|
isPublic Boolean? @default(true) @map("is_public")
|
|
|
|
|
owner Staff? @relation(fields: [ownerId], references: [id])
|
|
|
|
|
ownerId String? @map("owner_id")
|
|
|
|
|
deviceId String? @map("device_id")
|
|
|
|
|
device Device? @relation("DeviceResources", fields: [deviceId], references: [id])
|
2025-04-22 15:29:39 +08:00
|
|
|
|
|
2025-01-03 09:24:46 +08:00
|
|
|
|
// 索引
|
2024-12-31 15:57:32 +08:00
|
|
|
|
@@index([type])
|
2025-01-03 09:24:46 +08:00
|
|
|
|
@@index([createdAt])
|
2024-12-31 15:57:32 +08:00
|
|
|
|
@@map("resource")
|
2024-12-30 13:44:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-20 10:29:13 +08:00
|
|
|
|
model Device {
|
|
|
|
|
id String @id @default(cuid())
|
|
|
|
|
deptId String? @map("dept_id")
|
|
|
|
|
department Department? @relation("DeptDevice", fields: [deptId], references: [id])
|
|
|
|
|
showname String? @map("showname")
|
|
|
|
|
productType String? @map("product_type")
|
|
|
|
|
serialNumber String? @map("serial_number")
|
|
|
|
|
assetId String? @map("asset_id")
|
|
|
|
|
deviceStatus String? @map("device_status")
|
|
|
|
|
confidentialLabelId String? @map("confidential_label_id")
|
|
|
|
|
confidentialityLevel String? @map("confidentiality_level")
|
|
|
|
|
diskSerialNumber String? @map("disk_serial_number")
|
|
|
|
|
storageLocation String? @map("storage_location")
|
|
|
|
|
responsiblePerson String? @map("responsible_person")
|
|
|
|
|
notes String? @map("notes")
|
|
|
|
|
systemType String? @map("system_type")
|
|
|
|
|
deviceType String? @map("device_type")
|
|
|
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
|
deletedAt DateTime? @map("deleted_at")
|
2025-05-27 10:27:56 +08:00
|
|
|
|
resources Resource[] @relation("DeviceResources")
|
|
|
|
|
|
2025-05-20 10:29:13 +08:00
|
|
|
|
@@index([deptId])
|
|
|
|
|
@@index([systemType])
|
|
|
|
|
@@index([deviceType])
|
|
|
|
|
@@index([responsiblePerson])
|
|
|
|
|
@@map("device")
|
|
|
|
|
}
|