From 5954b9574268a761063c703c911c6f5cba18f98e Mon Sep 17 00:00:00 2001 From: Rao <1227431568@qq.com> Date: Mon, 21 Apr 2025 15:52:47 +0800 Subject: [PATCH] rht --- packages/common/prisma/schema.prisma | 321 --------------------------- 1 file changed, 321 deletions(-) diff --git a/packages/common/prisma/schema.prisma b/packages/common/prisma/schema.prisma index eba5ec8..fcac841 100755 --- a/packages/common/prisma/schema.prisma +++ b/packages/common/prisma/schema.prisma @@ -123,156 +123,7 @@ model AppConfig { @@map("app_config") } -model Post { - // 字符串类型字段 - id String @id @default(cuid()) // 帖子唯一标识,使用 cuid() 生成默认值 - type String? // Post类型,课程、章节、小节、讨论都用Post实现 - level String? - state String? - title String? // 帖子标题,可为空 - subTitle String? - content String? // 帖子内容,可为空 - important Boolean? //是否重要/精选/突出 - domainId String? @map("domain_id") - terms Term[] @relation("post_term") - order Float? @default(0) @map("order") - duration Int? - rating Int? @default(0) - students Staff[] @relation("post_student") - depts Department[] @relation("post_dept") - views Int @default(0) @map("views") - hates Int @default(0) @map("hates") - likes Int @default(0) @map("likes") - // 索引 - // 日期时间类型字段 - createdAt DateTime @default(now()) @map("created_at") - publishedAt DateTime? @map("published_at") // 发布时间 - updatedAt DateTime @map("updated_at") - deletedAt DateTime? @map("deleted_at") // 删除时间,可为空 - instructors PostInstructor[] - // 关系类型字段 - authorId String? @map("author_id") - author Staff? @relation(fields: [authorId], references: [id]) // 帖子作者,关联 Staff 模型 - enrollments Enrollment[] // 学生报名记录 - visits Visit[] // 访问记录,关联 Visit 模型 - parentId String? @map("parent_id") - parent Post? @relation("PostChildren", fields: [parentId], references: [id]) // 父级帖子,关联 Post 模型 - children Post[] @relation("PostChildren") // 子级帖子列表,关联 Post 模型 - hasChildren Boolean? @default(false) @map("has_children") - // 闭包表关系 - ancestors PostAncestry[] @relation("DescendantPosts") - descendants PostAncestry[] @relation("AncestorPosts") - resources Resource[] // 附件列表 - meta Json? // 封面url 视频url objectives具体的学习目标 rating评分Int - // 索引 - @@index([type, domainId]) - @@index([authorId, type]) - @@index([parentId, type]) - @@index([parentId, order]) - @@index([createdAt]) - @@index([updatedAt]) - @@index([type, publishedAt]) - @@index([state]) - @@index([level]) - @@index([views]) - @@index([important]) - @@map("post") -} - -model PostAncestry { - id String @id @default(cuid()) - ancestorId String? @map("ancestor_id") - descendantId String @map("descendant_id") - relDepth Int @map("rel_depth") - ancestor Post? @relation("AncestorPosts", fields: [ancestorId], references: [id]) - descendant Post @relation("DescendantPosts", fields: [descendantId], references: [id]) - - // 复合索引优化 - // 索引建议 - @@index([ancestorId]) // 针对祖先的查询 - @@index([descendantId]) // 针对后代的查询 - @@index([ancestorId, descendantId]) // 组合索引,用于查询特定的祖先-后代关系 - @@index([relDepth]) // 根据关系深度的查询 - @@map("post_ancestry") -} - -model Message { - id String @id @default(cuid()) - url String? - intent String? - option Json? - senderId String? @map("sender_id") - type String? - sender Staff? @relation(name: "message_sender", fields: [senderId], references: [id]) - title String? - content String? - receivers Staff[] @relation("message_receiver") - visits Visit[] - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime? @updatedAt @map("updated_at") - - @@index([type, createdAt]) - @@map("message") -} - -model Visit { - id String @id @default(cuid()) @map("id") - type String? - views Int @default(1) @map("views") - // sourceIP String? @map("source_ip") - // 关联关系 - visitorId String? @map("visitor_id") - visitor Staff? @relation(fields: [visitorId], references: [id]) - postId String? @map("post_id") - post Post? @relation(fields: [postId], references: [id]) - message Message? @relation(fields: [messageId], references: [id]) - messageId String? @map("message_id") - lectureId String? @map("lecture_id") // 课时ID - createdAt DateTime @default(now()) @map("created_at") // 创建时间 - updatedAt DateTime @updatedAt @map("updated_at") // 更新时间 - deletedAt DateTime? @map("deleted_at") // 删除时间,可为空 - meta Json? - - @@index([postId, type, visitorId]) - @@index([messageId, type, visitorId]) - @@map("visit") -} - -model Enrollment { - id String @id @default(cuid()) @map("id") - status String @map("status") - completionRate Float @default(0) @map("completion_rate") - - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") - completedAt DateTime? @map("completed_at") - - // 关联关系 - student Staff @relation(fields: [studentId], references: [id]) - studentId String @map("student_id") - post Post @relation(fields: [postId], references: [id]) - postId String @map("post_id") - - @@unique([studentId, postId]) - @@index([status]) - @@index([completedAt]) - @@map("enrollment") -} - -model PostInstructor { - postId String @map("post_id") - instructorId String @map("instructor_id") - role String @map("role") - createdAt DateTime @default(now()) @map("created_at") - order Float? @default(0) @map("order") - - post Post @relation(fields: [postId], references: [id]) - instructor Staff @relation(fields: [instructorId], references: [id]) - - @@id([postId, instructorId]) - @@map("post_instructor") -} model Resource { id String @id @default(cuid()) @map("id") @@ -302,104 +153,6 @@ model Resource { @@map("resource") } -model Node { - id String @id @default(cuid()) @map("id") - title String @map("title") - description String? @map("description") - type String @map("type") - style Json? @map("style") - position Json? @map("position") - data Json? @map("data") - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") - - // 关联关系 - sourceEdges NodeEdge[] @relation("source_node") - targetEdges NodeEdge[] @relation("target_node") - - @@map("node") -} - -model NodeEdge { - id String @id @default(cuid()) @map("id") - type String? @map("type") - label String? @map("label") - description String? @map("description") - style Json? @map("style") - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") - - source Node @relation("source_node", fields: [sourceId], references: [id], onDelete: Cascade) - sourceId String @map("source_id") - target Node @relation("target_node", fields: [targetId], references: [id], onDelete: Cascade) - targetId String @map("target_id") - - @@unique([sourceId, targetId, type]) - @@index([sourceId]) - @@index([targetId]) - @@map("node_edge") -} - -model TrainContent { - id String @id @default(cuid()) - title String @map("title") - trainSituations TrainSituation[] - trainPlans TrainPlan[] @relation("TrainPlanContent") - sportProjectId String? @unique @map("sport_project_id") // 新增字段,用于关联 SportProject - sportProject SportProject? @relation("TrainContentSportProject") // 可选的一对一关系 - type String @map("type") - parentId String? @map("parent_id") - parent TrainContent? @relation("ContentParent", fields: [parentId], references: [id]) // 指向自身 - children TrainContent[] @relation("ContentParent") // 指向自身 - deletedAt DateTime? @map("deleted_at") - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") - - @@map("train_content") -} - -model TrainSituation { - id String @id @default(cuid()) - - staffId String @map("staff_id") - staff Staff @relation(fields: [staffId], references: [id]) - trainContentId String @map("train_content_id") - trainContent TrainContent @relation(fields: [trainContentId], references: [id]) - groupId String? @map("group_id") - - score Float @default(0.0) @map("score") - value String? @map("value") - mustTrainTime Float @map("must_train_time") - alreadyTrainTime Float @map("already_train_time") - dailyTrainTime DailyTrainTime[] @relation("DailyTrainSituation") - - deletedAt DateTime? @map("deleted_at") - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") - - @@map("train_situation") -} - -model DailyTrainTime { - id String @id @default(cuid()) - trainSituationId String @map("train_situatio_id") - trainSituation TrainSituation @relation("DailyTrainSituation", fields: [trainSituationId], references: [id]) - trainTime Float @default(0.0) @map("trainTime") - createdAt DateTime @default(now()) @map("created_at") - - @@map("daily_train_situation") -} - -model Position { - id String @id @default(cuid()) @map("id") - type String @map("type") - categorize String @map("categorize") - staff Staff[] @relation("StaffPosition") - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") - - @@map("position") -} model Department { id String @id @default(cuid()) @@ -482,80 +235,6 @@ model Staff { @@map("staff") } -model TrainPlan { - id String @id @default(cuid()) - - trainDate DateTime @map("train_date") - trainTime DateTime @map("train_time") - trainType String @map("train_type") - trainContext String @map("train_context") - - trainContents TrainContent[] @relation("TrainPlanContent") - departmentId String? @map("department_id") - department Department? @relation("TrainPlanDept", fields: [departmentId], references: [id]) - - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") - deletedAt DateTime? @map("deleted_at") - - @@map("train_plan") -} - -model SportProject { - id String @id @default(cuid()) - name String @map("name") // 项目名称 - type String @map("type") // 项目类型 - description String? @map("description") // 项目描述 - unit String @map("unit") // 成绩单位(如:秒、米、个) - isAscending Boolean @map("is_ascending") // 是否为升序计分 - trainContentId String? @unique @map("train_content_id") // 新增字段,用于关联 TrainContent - trainContent TrainContent? @relation("TrainContentSportProject", fields: [trainContentId], references: [id]) // 可选的一对一关系 - standards SportStandard[] - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") - deletedAt DateTime? @map("deleted_at") - - @@map("sport_project") -} - -model SportStandard { - id String @id @default(cuid()) - - projectId String @map("project_id") - project SportProject @relation(fields: [projectId], references: [id]) - - gender Boolean @map("gender") // true为男,false为女 - personType String @map("person_type") // 人员类型 - - ageRanges Json @map("age_ranges") // 年龄段定义 - scoreTable Json @map("score_table") // 评分标准表 - - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") - deletedAt DateTime? @map("deleted_at") - - @@unique([projectId, gender, personType], name: "projectId_gender_personType") - @@map("sport_standard") -} - - - - - - - - - - - - - - - - - - - model Plan {