| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- // 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")
- }
- // User - status
- enum Status {
- ACTIVE
- INACTIVE
- }
- // User - sex
- enum Sex {
- FEMALE
- MALE
- }
- // Menu - type
- enum MenuType {
- DIRECTORY
- MENU
- BUTTON
- }
- // Log - method
- enum Method {
- GET
- POST
- PUT
- PATCH
- DELETE
- }
- // 系统管理 - 角色管理
- model Role {
- id String @id @default(uuid()) // 主键
- name String @unique // 角色名称
- code String @unique // 角色编码
- description String? // 角色描述
- sort Int // 排序
- permissions Permission[] // 与Permission的一对多关系
- createdAt DateTime @default(now()) // 创建时间
- updatedAt DateTime @updatedAt // 更新时间
- users User[] // 关联用户
- }
- // 系统管理 - 菜单管理
- model Menu {
- id String @id @default(uuid()) // 主键
- title String // 菜单名称
- type MenuType @default(MENU) // 菜单类型
- parentId String?
- parent Menu? @relation(name: "MenuHierarchy", fields: [parentId], references: [id])
- name String? @unique // 路由名称
- path String? @unique // 路由地址
- component String? // 组件路径
- meta Json? // 路由元信息(JSON 对象)
- props Json? // Iframe 页面参数(JSON 对象)
- sort Int // 排序
- permission String? @unique // 权限标识
- permissions Permission[] // 与Permission的一对多关系
- createdAt DateTime @default(now()) // 创建时间
- updatedAt DateTime @updatedAt // 更新时间
- children Menu[] @relation(name: "MenuHierarchy")
- }
- // 系统管理 - 权限管理
- model Permission {
- id String @id @default(uuid()) // 主键
- roleId String // 角色ID
- menuId String // 菜单ID
- createdAt DateTime @default(now()) // 创建时间
- role Role @relation(fields: [roleId], references: [id]) // 与Role的关联
- menu Menu @relation(fields: [menuId], references: [id]) // 与Menu的关联
- }
- // 智能行政 - 组织管理
- model Organization {
- id String @id @default(uuid()) // 主键
- name String @unique // 组织名称
- code String @unique // 组织编码
- parentId String?
- parent Organization? @relation(name: "OrgHierarchy", fields: [parentId], references: [id])
- // users User[] // 关联用户
- sort Int // 排序
- description String? // 组织描述
- icon String? // 组织图标
- posts Post[] // 岗位
- createdAt DateTime @default(now()) // 创建时间
- updatedAt DateTime @updatedAt // 更新时间
- children Organization[] @relation(name: "OrgHierarchy")
- }
- // 智能行政 - 岗位管理
- model Post {
- id String @id @default(uuid()) // 主键
- name String @unique // 岗位名称
- orgId String // 关联的组织 id
- organization Organization @relation(fields: [orgId], references: [id])
- parentId String?
- parent Post? @relation(name: "PostHierarchy", fields: [parentId], references: [id])
- // users User[] // 关联用户
- sort Int // 排序
- description String? // 岗位描述
- createdAt DateTime @default(now()) // 创建时间
- updatedAt DateTime @updatedAt // 更新时间
- children Post[] @relation(name: "PostHierarchy")
- }
- // 系统管理 - 用户管理
- model User {
- id String @id @default(uuid()) // 主键
- userName String @unique // 用户名
- password String // 密码
- cnName String // 中文名
- email String @unique // 电子邮箱
- phone String @unique // 手机号
- avatar String // 头像
- sex Sex @default(FEMALE) // 性别
- status Status @default(ACTIVE) // 状态
- sort Int // 排序
- token String? // token
- tags String[] @default([]) // 标签
- city String[] @default([]) // 城市
- address String? // 详细地址
- roleId String // 关联的角色 id
- role Role @relation(fields: [roleId], references: [id])
- // orgId String // 关联的组织 id
- // organization Organization @relation(fields: [orgId], references: [id])
- // postId String // 关联的岗位 id
- // post Post @relation(fields: [postId], references: [id])
- logs Log[] // 操作日志
- loginCount Int @default(0) // 登录次数
- lastIp String? // 最后登录ip
- lastLoginAt DateTime? // 最后登录时间
- messages Message[] // 该用户发布的消息列表
- messageReads MessageRead[] // 关联已读列表
- createdAt DateTime @default(now()) // 创建时间
- updatedAt DateTime @updatedAt // 更新时间
- }
- // 系统管理 - 操作日志
- model Log {
- id String @id @default(uuid()) // 主键
- userId String // 关联的用户 id
- user User @relation(fields: [userId], references: [id])
- ip String // ip
- action String // 请求地址
- method Method // 请求方法
- params Json // 请求参数(JSON 对象)
- os String // 系统
- browser String // 浏览器
- province String? // 所在省份
- city String? // 所在城市
- adcode String? // 城市编码
- createdAt DateTime @default(now()) // 创建时间
- }
- // 智能行政 - 消息公告
- model Message {
- id String @id @default(uuid()) // 主键
- title String // 标题
- content String // 内容
- status Status @default(ACTIVE) // 状态
- pinned Boolean @default(false)
- userId String // 作者 id
- user User @relation(fields: [userId], references: [id])
- messageReads MessageRead[] // 关联已读列表
- createdAt DateTime @default(now()) // 创建时间
- updatedAt DateTime @updatedAt // 更新时间
- }
- // 智能行政 - 消息公告 - 已读列表
- model MessageRead {
- id String @id @default(uuid()) // 主键
- messageId String // 消息 id
- message Message @relation(fields: [messageId], references: [id])
- userId String // 用户 id
- user User @relation(fields: [userId], references: [id])
- createdAt DateTime @default(now()) // 创建时间
- }
- // 系统管理 - 国际化
- model Internalization {
- id String @id @default(uuid()) // 主键
- name String // 键
- parentId String?
- parent Internalization? @relation(name: "InternalizationHierarchy", fields: [parentId], references: [id])
- zhCN String? // 中文
- enUS String? // 英文
- jaJP String? // 日文
- zhTW String? // 繁体中文
- createdAt DateTime @default(now()) // 创建时间
- updatedAt DateTime @updatedAt // 更新时间
- children Internalization[] @relation(name: "InternalizationHierarchy")
- }
- // 激活码管理
- model ActivationCode {
- id Int @id @default(autoincrement()) // 自增主键ID
- code String @unique // 激活码唯一字符串
- type Int // 原激活码类型
- typeId String? // 新激活码类型id
- codeType ActivationCodeType? @relation(fields: [typeId], references: [id]) // 关联激活码类型
- importedAt DateTime @default(now()) // 导入时间
- activated Boolean @default(false) // 是否已激活
- activatedAt DateTime? // 激活时间(可为空)
- refunded Boolean @default(false) // 是否已退款
- refundedAt DateTime? // 退款时间(可为空)
- refundNote String? // 退款备注(例如原因)
- revoked Boolean @default(false) // 是否已收回
- revokedAt DateTime? // 收回时间(可为空)
- dataDate DateTime? // 数据日期,用于数据归属时间
- @@index([type])
- @@index([dataDate])
- @@index([activated, refunded, revoked])
- }
- model ActivationCodeType {
- id String @id @default(uuid()) // 主键
- name String @unique // 类型名称(添加唯一约束)
- activationCodes ActivationCode[] // 反向关联激活码
- createdAt DateTime @default(now()) // 创建时间
- updatedAt DateTime @updatedAt // 更新时间
- }
|