schema.prisma 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. // This is your Prisma schema file,
  2. // learn more about it in the docs: https://pris.ly/d/prisma-schema
  3. // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
  4. // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
  5. generator client {
  6. provider = "prisma-client-js"
  7. }
  8. datasource db {
  9. provider = "postgresql"
  10. url = env("DATABASE_URL")
  11. }
  12. // User - status
  13. enum Status {
  14. ACTIVE
  15. INACTIVE
  16. }
  17. // User - sex
  18. enum Sex {
  19. FEMALE
  20. MALE
  21. }
  22. // Menu - type
  23. enum MenuType {
  24. DIRECTORY
  25. MENU
  26. BUTTON
  27. }
  28. // Log - method
  29. enum Method {
  30. GET
  31. POST
  32. PUT
  33. PATCH
  34. DELETE
  35. }
  36. // 系统管理 - 角色管理
  37. model Role {
  38. id String @id @default(uuid()) // 主键
  39. name String @unique // 角色名称
  40. code String @unique // 角色编码
  41. description String? // 角色描述
  42. sort Int // 排序
  43. permissions Permission[] // 与Permission的一对多关系
  44. createdAt DateTime @default(now()) // 创建时间
  45. updatedAt DateTime @updatedAt // 更新时间
  46. users User[] // 关联用户
  47. }
  48. // 系统管理 - 菜单管理
  49. model Menu {
  50. id String @id @default(uuid()) // 主键
  51. title String // 菜单名称
  52. type MenuType @default(MENU) // 菜单类型
  53. parentId String?
  54. parent Menu? @relation(name: "MenuHierarchy", fields: [parentId], references: [id])
  55. name String? @unique // 路由名称
  56. path String? @unique // 路由地址
  57. component String? // 组件路径
  58. meta Json? // 路由元信息(JSON 对象)
  59. props Json? // Iframe 页面参数(JSON 对象)
  60. sort Int // 排序
  61. permission String? @unique // 权限标识
  62. permissions Permission[] // 与Permission的一对多关系
  63. createdAt DateTime @default(now()) // 创建时间
  64. updatedAt DateTime @updatedAt // 更新时间
  65. children Menu[] @relation(name: "MenuHierarchy")
  66. }
  67. // 系统管理 - 权限管理
  68. model Permission {
  69. id String @id @default(uuid()) // 主键
  70. roleId String // 角色ID
  71. menuId String // 菜单ID
  72. createdAt DateTime @default(now()) // 创建时间
  73. role Role @relation(fields: [roleId], references: [id]) // 与Role的关联
  74. menu Menu @relation(fields: [menuId], references: [id]) // 与Menu的关联
  75. }
  76. // 智能行政 - 组织管理
  77. model Organization {
  78. id String @id @default(uuid()) // 主键
  79. name String @unique // 组织名称
  80. code String @unique // 组织编码
  81. parentId String?
  82. parent Organization? @relation(name: "OrgHierarchy", fields: [parentId], references: [id])
  83. // users User[] // 关联用户
  84. sort Int // 排序
  85. description String? // 组织描述
  86. icon String? // 组织图标
  87. posts Post[] // 岗位
  88. createdAt DateTime @default(now()) // 创建时间
  89. updatedAt DateTime @updatedAt // 更新时间
  90. children Organization[] @relation(name: "OrgHierarchy")
  91. }
  92. // 智能行政 - 岗位管理
  93. model Post {
  94. id String @id @default(uuid()) // 主键
  95. name String @unique // 岗位名称
  96. orgId String // 关联的组织 id
  97. organization Organization @relation(fields: [orgId], references: [id])
  98. parentId String?
  99. parent Post? @relation(name: "PostHierarchy", fields: [parentId], references: [id])
  100. // users User[] // 关联用户
  101. sort Int // 排序
  102. description String? // 岗位描述
  103. createdAt DateTime @default(now()) // 创建时间
  104. updatedAt DateTime @updatedAt // 更新时间
  105. children Post[] @relation(name: "PostHierarchy")
  106. }
  107. // 系统管理 - 用户管理
  108. model User {
  109. id String @id @default(uuid()) // 主键
  110. userName String @unique // 用户名
  111. password String // 密码
  112. cnName String // 中文名
  113. email String @unique // 电子邮箱
  114. phone String @unique // 手机号
  115. avatar String // 头像
  116. sex Sex @default(FEMALE) // 性别
  117. status Status @default(ACTIVE) // 状态
  118. sort Int // 排序
  119. token String? // token
  120. tags String[] @default([]) // 标签
  121. city String[] @default([]) // 城市
  122. address String? // 详细地址
  123. roleId String // 关联的角色 id
  124. role Role @relation(fields: [roleId], references: [id])
  125. // orgId String // 关联的组织 id
  126. // organization Organization @relation(fields: [orgId], references: [id])
  127. // postId String // 关联的岗位 id
  128. // post Post @relation(fields: [postId], references: [id])
  129. logs Log[] // 操作日志
  130. loginCount Int @default(0) // 登录次数
  131. lastIp String? // 最后登录ip
  132. lastLoginAt DateTime? // 最后登录时间
  133. messages Message[] // 该用户发布的消息列表
  134. messageReads MessageRead[] // 关联已读列表
  135. createdAt DateTime @default(now()) // 创建时间
  136. updatedAt DateTime @updatedAt // 更新时间
  137. }
  138. // 系统管理 - 操作日志
  139. model Log {
  140. id String @id @default(uuid()) // 主键
  141. userId String // 关联的用户 id
  142. user User @relation(fields: [userId], references: [id])
  143. ip String // ip
  144. action String // 请求地址
  145. method Method // 请求方法
  146. params Json // 请求参数(JSON 对象)
  147. os String // 系统
  148. browser String // 浏览器
  149. province String? // 所在省份
  150. city String? // 所在城市
  151. adcode String? // 城市编码
  152. createdAt DateTime @default(now()) // 创建时间
  153. }
  154. // 智能行政 - 消息公告
  155. model Message {
  156. id String @id @default(uuid()) // 主键
  157. title String // 标题
  158. content String // 内容
  159. status Status @default(ACTIVE) // 状态
  160. pinned Boolean @default(false)
  161. userId String // 作者 id
  162. user User @relation(fields: [userId], references: [id])
  163. messageReads MessageRead[] // 关联已读列表
  164. createdAt DateTime @default(now()) // 创建时间
  165. updatedAt DateTime @updatedAt // 更新时间
  166. }
  167. // 智能行政 - 消息公告 - 已读列表
  168. model MessageRead {
  169. id String @id @default(uuid()) // 主键
  170. messageId String // 消息 id
  171. message Message @relation(fields: [messageId], references: [id])
  172. userId String // 用户 id
  173. user User @relation(fields: [userId], references: [id])
  174. createdAt DateTime @default(now()) // 创建时间
  175. }
  176. // 系统管理 - 国际化
  177. model Internalization {
  178. id String @id @default(uuid()) // 主键
  179. name String // 键
  180. parentId String?
  181. parent Internalization? @relation(name: "InternalizationHierarchy", fields: [parentId], references: [id])
  182. zhCN String? // 中文
  183. enUS String? // 英文
  184. jaJP String? // 日文
  185. zhTW String? // 繁体中文
  186. createdAt DateTime @default(now()) // 创建时间
  187. updatedAt DateTime @updatedAt // 更新时间
  188. children Internalization[] @relation(name: "InternalizationHierarchy")
  189. }
  190. // 激活码管理
  191. model ActivationCode {
  192. id Int @id @default(autoincrement()) // 自增主键ID
  193. code String @unique // 激活码唯一字符串
  194. type Int // 原激活码类型
  195. typeId String? // 新激活码类型id
  196. codeType ActivationCodeType? @relation(fields: [typeId], references: [id]) // 关联激活码类型
  197. importedAt DateTime @default(now()) // 导入时间
  198. activated Boolean @default(false) // 是否已激活
  199. activatedAt DateTime? // 激活时间(可为空)
  200. refunded Boolean @default(false) // 是否已退款
  201. refundedAt DateTime? // 退款时间(可为空)
  202. refundNote String? // 退款备注(例如原因)
  203. revoked Boolean @default(false) // 是否已收回
  204. revokedAt DateTime? // 收回时间(可为空)
  205. dataDate DateTime? // 数据日期,用于数据归属时间
  206. @@index([type])
  207. @@index([dataDate])
  208. @@index([activated, refunded, revoked])
  209. }
  210. model ActivationCodeType {
  211. id String @id @default(uuid()) // 主键
  212. name String @unique // 类型名称(添加唯一约束)
  213. activationCodes ActivationCode[] // 反向关联激活码
  214. createdAt DateTime @default(now()) // 创建时间
  215. updatedAt DateTime @updatedAt // 更新时间
  216. }