Files
stu-ai-demo/prisma/schema.prisma
liuyh 5020bd1532 feat: Hair Keeper v1.1.0 版本更新
本次更新包含以下主要改进:

## 新功能
- 添加quickstart.sh脚本帮助用户快速使用模板项目
- 添加simple_deploy.sh便于部署
- 新增院系管理功能(DeptAdmin),支持增删改查院系管理员信息
- 用户可以在header中切换管理的院系
- 添加zustand全局状态管理
- 添加DEFAULT_USER_PASSWORD环境变量,作为创建用户时的默认密码
- 添加p-limit库和DB_PARALLEL_LIMIT环境变量控制数据库批次操作并发数

## 安全修复
- 修复Next.js CVE-2025-66478漏洞
- 限制只有超级管理员才能创建超级管理员用户

## 开发环境优化
- 开发终端兼容云端环境
- MinIO客户端直传兼容云端环境
- 开发容器增加vim和Claude Code插件
- 编程代理改用Claude
- docker-compose.yml添加全局name属性

## Bug修复与代码优化
- 删除用户时级联删除SelectionLog
- 手机端关闭侧边栏后刷新页面延迟调整(300ms=>350ms)
- instrumentation.ts移至src内部以适配生产环境
- 删除部分引发类型错误的无用代码
- 优化quickstart.sh远程仓库推送相关配置

## 文件变更
- 新增49个文件,修改多个配置和源代码文件
- 重构用户管理模块目录结构

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-23 16:58:55 +08:00

267 lines
9.6 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// 用户表
model User {
id String @id
name String?
status String? // 在校/减离/NULL
deptCode String? @map("dept_code") // 所属院系代码(外键)
currentManagedDept String? @map("current_managed_dept") @db.VarChar(5) // 当前正在管理的院系代码,用于支持院系管理员类型的角色
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz
password String
isSuperAdmin Boolean @default(false) @map("is_super_admin")
lastLoginAt DateTime? @map("last_login_at") @db.Timestamptz
// 关联
dept Dept? @relation(fields: [deptCode], references: [code])
roles Role[] // 多对多关联角色
selectionLogs SelectionLog[] // 选择日志
deptAdmins DeptAdmin[] // 作为院系管理员的信息
@@map("user")
}
// 院系表
model Dept {
code String @id
name String @default("")
fullName String @default("") @map("full_name")
// 关联
users User[]
deptAdmins DeptAdmin[] // 院系管理员
@@map("dept")
}
// 院系管理员表
model DeptAdmin {
id Int @id @default(autoincrement())
uid String @db.VarChar(30) // 管理员用户ID外键
deptCode String @map("dept_code") @db.VarChar(5) // 院系代码(外键)
adminEmail String? @map("admin_email") @db.VarChar(100) // 管理员邮箱
adminLinePhone String? @map("admin_line_phone") @db.VarChar(100) // 管理员座机
adminMobilePhone String? @map("admin_mobile_phone") @db.VarChar(100) // 管理员手机
note String? @db.VarChar(1000) // 备注
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz
// 关联
user User @relation(fields: [uid], references: [id])
dept Dept @relation(fields: [deptCode], references: [code])
@@unique([uid, deptCode], name: "uidx_uid_dept_code")
@@map("dept_admin")
}
// 角色表
model Role {
id Int @id @default(autoincrement())
name String @unique
users User[] // 多对多关联用户
permissions Permission[] // 多对多关联权限
@@map("role")
}
// 权限表
model Permission {
id Int @id @default(autoincrement())
name String @unique
roles Role[] // 多对多关联角色
@@map("permission")
}
// 选择日志表
model SelectionLog {
id Int @id @default(autoincrement())
userId String // 关联到用户
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
// 用于标识是哪个的选项,用.进行分隔,例如"user.filter.dept"
context String
// 关键字段:被选中的选项的值
optionId String @map("option_id")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
// 建立索引,提升查询性能
@@index([userId, context])
@@index([context, optionId])
@@map("selection_log")
}
// KV配置表 - 用于存储各种键值对配置
model KVConfig {
key String @id // 配置键
value String @db.Text // 配置值
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz
@@map("kv_config")
}
/*********************************************** 仅在开发阶段可用的数据表放在这下面 ***********************************************/
model DevFileType {
id String @id // 文件类型ID如 "COMPONENT_UI"
name String // 文件类型名称,如 "UI组件"
description String // 文件类型描述
order Int // 用来进行排序方便展示
// 关联
files DevAnalyzedFile[]
@@map("dev_file_type")
}
// 依赖包类型表
model DevPkgType {
id String @id // 依赖包类型ID如 "CORE_FRAMEWORK"
name String // 分类名称,如 "核心框架 (Core Framework)"
description String @db.Text // 职责描述
order Int // 用来进行排序方便展示
packages DevAnalyzedPkg[]
@@map("dev_pkg_type")
}
// 分析得到的项目文件信息
model DevAnalyzedFile {
id Int @id @default(autoincrement())
path String // 文件相对路径,如 "src/app/api/trpc/[trpc]/route.ts"
fileName String // 文件名,如 "route.ts"
commitId String @default("") @map("commit_id") // Git commit ID (前7位修改过的文件后面加*)
content String? @db.Text // 文件内容不超过100K的非二进制文件
fileTypeId String @map("file_type_id") // 文件类型ID外键
summary String // 主要功能一句话总结 (LLM生成)
description String // 详细功能描述 (LLM生成)
// 关键代码信息
exportedMembers Json? // 导出的函数、组件、类型、对象、列表、其他 { name, type }[]
// 元数据
tags String[] // 标签 (用于快速筛选和分类)
lastAnalyzedAt DateTime @updatedAt @db.Timestamptz
createdAt DateTime @default(now()) @db.Timestamptz // 创建时间
// 关联
fileType DevFileType @relation(fields: [fileTypeId], references: [id])
dependencies DevFileDependency[] // 该文件依赖的其他文件
pkgDependencies DevFilePkgDependency[] // 该文件依赖的包
// path 和 commitId 构成唯一键
@@unique([path, commitId], name: "uidx_path_commit")
@@map("dev_analyzed_file")
}
// 分析得到的依赖包信息
model DevAnalyzedPkg {
name String @id // 包名,如 '@tanstack/react-table'
// -- 静态信息通过读取node_modules中包的package.json获取内置包则为node的信息
version String // 版本号,如 '8.17.3'
modifiedAt DateTime // 该版本的发布时间,通过命令获取 npm view @tanstack/react-table "time[8.17.3]"
description String @db.Text // 从 package.json 中获取的官方描述
homepage String? // 包的主页URL
repositoryUrl String? @map("repository_url") // 包的仓库URL例如git+https://github.com/shadcn/ui.git
// -- 调用AI获取
pkgTypeId String @map("pkg_type_id") // 依赖包类型ID (外键)
projectRoleSummary String @db.Text // AI总结的该包的核心功能
primaryUsagePattern String @db.Text // AI总结的主要使用模式分成多点描述
// -- 统计获得
relatedFiles String[] // path[] 本次分析中,认为和该库有关联的文件(统计一定引用层数)
relatedFileCount Int // 该包在项目中被多少个文件直接或引用
// --- 时间戳 ---
lastAnalyzedAt DateTime @updatedAt @map("last_analyzed_at") @db.Timestamptz
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
// --- 关联 ---
pkgType DevPkgType @relation(fields: [pkgTypeId], references: [id])
@@index([pkgTypeId])
@@map("dev_analyzed_pkg")
}
// 文件依赖关系表
model DevFileDependency {
id Int @id @default(autoincrement())
sourceFileId Int @map("source_file_id") // 源文件ID依赖方
targetFilePath String @map("target_file_path") // 目标文件路径(被依赖方)
// AI生成的依赖用途描述
usageDescription String? @map("usage_description") @db.Text // 描述该依赖在源文件中的用途
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
// 关联
sourceFile DevAnalyzedFile @relation(fields: [sourceFileId], references: [id], onDelete: Cascade)
// 确保同一个源文件不会重复依赖同一个目标文件
@@unique([sourceFileId, targetFilePath], name: "uidx_source_target")
@@index([targetFilePath]) // 加速按目标文件路径查询
@@map("dev_file_dependency")
}
// 包依赖关系表
model DevFilePkgDependency {
id Int @id @default(autoincrement())
sourceFileId Int @map("source_file_id") // 源文件ID依赖方
packageName String @map("package_name") // 包名(如 'react' 或 '@tanstack/react-table'
// AI生成的依赖用途描述
usageDescription String? @map("usage_description") @db.Text // 描述该包在源文件中的用途和使用的功能
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
// 关联
sourceFile DevAnalyzedFile @relation(fields: [sourceFileId], references: [id], onDelete: Cascade)
// 确保同一个源文件不会重复依赖同一个包
@@unique([sourceFileId, packageName], name: "uidx_source_package")
@@index([packageName]) // 加速按包名查询
@@map("dev_file_pkg_dependency")
}
// 分析得到的项目文件夹信息
model DevAnalyzedFolder {
path String @id // 文件夹相对路径,如 "src/app/api"
name String // 文件夹名,如 "api"
summary String // 主要功能一句话总结 (LLM生成)
description String @db.Text // 详细功能描述 (LLM生成)
// 元数据
lastAnalyzedAt DateTime @updatedAt @map("last_analyzed_at") @db.Timestamptz
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
@@map("dev_analyzed_folder")
}