351 lines
13 KiB
Plaintext
Executable File
351 lines
13 KiB
Plaintext
Executable File
// This is your Prisma schema file,
|
||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||
|
||
generator client {
|
||
provider = "prisma-client-js"
|
||
}
|
||
|
||
datasource db {
|
||
provider = "postgresql"
|
||
url = env("DATABASE_URL")
|
||
}
|
||
|
||
model Taxonomy {
|
||
id String @id @default(cuid())
|
||
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")
|
||
|
||
@@index([order, deletedAt])
|
||
@@map("taxonomy")
|
||
}
|
||
|
||
model Term {
|
||
id String @id @default(cuid())
|
||
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")
|
||
plan Plan? @relation(fields: [planId], references: [id])
|
||
planId String?
|
||
plans Plan[] @relation("plan_term")
|
||
trainPlans TrainPlan[] @relation("TrainPlanTerm")
|
||
majorId String? @map("major_id")
|
||
major Outline? @relation("major_term", fields: [majorId], references: [id])
|
||
identityId String? @map("identity_id")
|
||
identity Outline? @relation("identity_term", fields: [identityId], references: [id])
|
||
subjectId String? @map("subject_id")
|
||
subject Outline? @relation("subject_term", fields: [subjectId], references: [id])
|
||
courses Course[] @relation("course_term")
|
||
|
||
@@index([name]) // 对name字段建立索引,以加快基于name的查找速度
|
||
@@index([parentId]) // 对parentId字段建立索引,以加快基于parentId的查找速度
|
||
@@map("term")
|
||
|
||
|
||
}
|
||
|
||
model TermAncestry {
|
||
id String @id @default(cuid())
|
||
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])
|
||
|
||
// 索引建议
|
||
@@index([ancestorId]) // 针对祖先的查询
|
||
@@index([descendantId]) // 针对后代的查询
|
||
@@index([ancestorId, descendantId]) // 组合索引,用于查询特定的祖先-后代关系
|
||
@@index([relDepth]) // 根据关系深度的查询
|
||
@@map("term_ancestry")
|
||
}
|
||
|
||
model DeptAncestry {
|
||
id String @id @default(cuid())
|
||
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")
|
||
}
|
||
|
||
model RoleMap {
|
||
id String @id @default(cuid())
|
||
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")
|
||
}
|
||
|
||
model Role {
|
||
id String @id @default(cuid())
|
||
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 {
|
||
id String @id @default(cuid())
|
||
slug String @unique
|
||
title String?
|
||
description String?
|
||
meta Json?
|
||
|
||
@@map("app_config")
|
||
}
|
||
|
||
model Resource {
|
||
id String @id @default(cuid()) @map("id")
|
||
title String? @map("title")
|
||
description String? @map("description")
|
||
type String? @map("type")
|
||
fileId String? @unique
|
||
url String?
|
||
// 元数据
|
||
meta Json? @map("meta")
|
||
// 处理状态控制
|
||
status String?
|
||
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")
|
||
|
||
// 索引
|
||
@@index([type])
|
||
@@index([createdAt])
|
||
@@map("resource")
|
||
}
|
||
|
||
model Department {
|
||
id String @id @default(cuid())
|
||
name String
|
||
order Float?
|
||
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")
|
||
progress Json? @map("progress") //单位训练进度表
|
||
score Json? @map("score") //单位成绩评定表
|
||
|
||
|
||
// watchedPost Post[] @relation("post_watch_dept")
|
||
hasChildren Boolean? @default(false) @map("has_children")
|
||
|
||
planId String?
|
||
plans Plan[] @relation("plan_dept")
|
||
|
||
@@index([parentId])
|
||
@@index([isDomain])
|
||
@@index([name])
|
||
@@index([order])
|
||
@@map("department")
|
||
}
|
||
|
||
model Staff {
|
||
id String @id @default(cuid())
|
||
showname String? @map("showname")
|
||
username String @unique @map("username")
|
||
avatar String? @map("avatar")
|
||
password String? @map("password")
|
||
phoneNumber String? @unique @map("phone_number")
|
||
age Int? @default(22) @map("age")
|
||
gender Int? @default(1) @map("gender")
|
||
absent Boolean? @default(false) @map("absent")
|
||
subjects Subject[] @relation("staff_subject")
|
||
domainId String? @map("domain_id")
|
||
deptId String? @map("dept_id")
|
||
outlines Outline[] @relation("staff_outline")
|
||
alreadyTime Json? @map("already_time") //个人训练进度表
|
||
score Json? @map("score") //个人成绩评定表
|
||
|
||
domain Department? @relation("DomainStaff", fields: [domainId], references: [id])
|
||
department Department? @relation("DeptStaff", fields: [deptId], references: [id])
|
||
order Float?
|
||
|
||
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")
|
||
|
||
// watchedPost Post[] @relation("post_watch_staff")
|
||
|
||
registerToken String?
|
||
ownedResources Resource[]
|
||
plans Plan[]
|
||
|
||
@@index([officerId])
|
||
@@index([deptId])
|
||
@@index([domainId])
|
||
@@index([username])
|
||
@@index([order])
|
||
@@map("staff")
|
||
}
|
||
|
||
model Plan {
|
||
id String @id @default(cuid())
|
||
authorId String? @map("author_id")
|
||
author Staff? @relation(fields: [authorId], references: [id]) // 帖子作者,关联 Staff 模型
|
||
|
||
createdAt DateTime @default(now()) @map("created_at")
|
||
publishedAt DateTime? @map("published_at") // 发布时间
|
||
updatedAt DateTime @map("updated_at")
|
||
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
|
||
|
||
terms Term[] @relation("plan_term")
|
||
termRefs Term[]
|
||
checked Boolean @default(false) @map("checked")
|
||
depts Department[] @relation("plan_dept")
|
||
meta Json? @map("meta") // 计划表
|
||
trainPlans TrainPlan[]
|
||
|
||
@@map("plan")
|
||
}
|
||
|
||
model TrainPlan {
|
||
id String @id @default(cuid())
|
||
|
||
createdAt DateTime @default(now()) @map("created_at")
|
||
updatedAt DateTime @map("updated_at")
|
||
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
|
||
|
||
planId String @map("plan_id")
|
||
plan Plan @relation(fields: [planId], references: [id])
|
||
|
||
terms Term[] @relation("TrainPlanTerm")
|
||
day DateTime? @map("day") // 日期
|
||
dayType String? @map("day_type") // 早中晚
|
||
outlines Outline[] @relation("train_plan_outline")
|
||
trainTime Float? @map("train_time") // 培训时长
|
||
content String? @map("content") // 内容
|
||
meta Json? @map("meta") // 其他信息
|
||
|
||
@@index([day])
|
||
@@map("train_plan")
|
||
}
|
||
|
||
model Outline {
|
||
id String @id @default(cuid())
|
||
|
||
major Term[] @relation("major_term") //专业
|
||
identity Term[] @relation("identity_term") //身份
|
||
subject Term[] @relation("subject_term") //科目
|
||
courses Course[] @relation("course") //课目
|
||
daytime Float? @map("day_time") //昼间时长
|
||
nighttime Float? @map("night_time") //夜间时长
|
||
|
||
createdAt DateTime @default(now()) @map("created_at")
|
||
updatedAt DateTime @map("updated_at")
|
||
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
|
||
|
||
staffs Staff[] @relation("staff_outline")
|
||
trainplans TrainPlan[] @relation("train_plan_outline")
|
||
}
|
||
|
||
model Course {
|
||
id String @id @default(cuid())
|
||
|
||
outlineId String? @map("course_id")
|
||
outline Outline? @relation("course", fields: [outlineId], references: [id])
|
||
terms Term[] @relation("course_term")
|
||
daytime Float? @map("day_time") //昼间时长
|
||
nighttime Float? @map("night_time") //夜间时长
|
||
score String? @map("score") //成绩标准
|
||
|
||
createdAt DateTime @default(now()) @map("created_at")
|
||
updatedAt DateTime @map("updated_at")
|
||
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
|
||
|
||
@@map("course")
|
||
@@index([score])
|
||
}
|
||
|
||
model Sport{
|
||
id String @id @default(cuid())
|
||
|
||
type String? @map("type") // 基础、站斗、实用
|
||
name String? @map("name") // 名称
|
||
standard Json? @map("standard") // 标准
|
||
|
||
|
||
createdAt DateTime @default(now()) @map("created_at")
|
||
updatedAt DateTime @map("updated_at")
|
||
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
|
||
}
|
||
|
||
model Subject {
|
||
id String @id @default(cuid())
|
||
name String @map("name")
|
||
parentId String? @map("parent_id")
|
||
parent Subject? @relation("SubjectChildren", fields: [parentId], references: [id]) // 父级帖子,关联 Post 模型
|
||
children Subject[] @relation("SubjectChildren") // 子级帖子列表,关联 Post 模型
|
||
ancestors SubjectAncestry[] @relation("DescendantToAncestor")
|
||
descendants SubjectAncestry[] @relation("AncestorToDescendant")
|
||
staffs Staff[] @relation("staff_subject")
|
||
|
||
@@map("subject")
|
||
}
|
||
|
||
model SubjectAncestry {
|
||
id String @id @default(cuid())
|
||
relDepth Int @map("rel_depth")
|
||
ancestorId String? @map("ancestor_id")
|
||
ancestor Subject? @relation("DescendantToAncestor", fields: [ancestorId], references: [id])
|
||
descendantId String @map("descendant_id")
|
||
descendant Subject @relation("AncestorToDescendant", fields: [descendantId], references: [id])
|
||
|
||
@@index([ancestorId])
|
||
@@index([descendantId])
|
||
@@index([ancestorId, descendantId])
|
||
@@map("subject_ancestry")
|
||
}
|