schema.prisma 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. generator client {
  2. provider = "prisma-client-js"
  3. }
  4. datasource db {
  5. provider = "mysql"
  6. url = env("DATABASE_URL")
  7. }
  8. model User {
  9. id Int @id @default(autoincrement())
  10. phone String? @unique
  11. openid String? @unique
  12. nickname String @default("用户")
  13. avatar String @default("")
  14. memberLevel Int @default(0)
  15. memberExpireAt DateTime?
  16. dailyUsage Int @default(0)
  17. lastUsageDate String @default("")
  18. createdAt DateTime @default(now())
  19. updatedAt DateTime @updatedAt
  20. usedAudioMinutes Int @default(0)
  21. subscriptionResetDate DateTime?
  22. comments Comment[]
  23. drafts Draft[]
  24. favorites Favorite[]
  25. notifications Notification[]
  26. orders Order[]
  27. playRecords PlayRecord[]
  28. playlists Playlist[]
  29. signRecords SignRecord[]
  30. subscriptions Subscription[]
  31. tokenBalance TokenBalance?
  32. tokenUsages TokenUsage[]
  33. preferences UserPreference?
  34. @@index([phone])
  35. @@index([openid])
  36. }
  37. model Order {
  38. id Int @id @default(autoincrement())
  39. userId Int
  40. orderNo String @unique
  41. planId Int?
  42. productType String
  43. amount Decimal @db.Decimal(10, 2)
  44. status String @default("pending")
  45. paymentMethod String?
  46. paymentId String?
  47. paidAt DateTime?
  48. createdAt DateTime @default(now())
  49. updatedAt DateTime @updatedAt
  50. plan SubscriptionPlan? @relation(fields: [planId], references: [id])
  51. user User @relation(fields: [userId], references: [id])
  52. tokenUsages TokenUsage[]
  53. @@index([userId, createdAt])
  54. @@index([orderNo])
  55. @@index([status])
  56. @@index([planId], map: "Order_planId_fkey")
  57. }
  58. model PlayRecord {
  59. id Int @id @default(autoincrement())
  60. userId Int
  61. chapterId Int
  62. progress Float @default(0)
  63. duration Float @default(0)
  64. updatedAt DateTime @updatedAt
  65. createdAt DateTime @default(now())
  66. chapter BookChapter @relation(fields: [chapterId], references: [id])
  67. user User @relation(fields: [userId], references: [id])
  68. @@unique([userId, chapterId])
  69. @@index([userId])
  70. @@index([chapterId])
  71. }
  72. model UserPreference {
  73. id Int @id @default(autoincrement())
  74. userId Int @unique
  75. playSpeed Float @default(1)
  76. quality String @default("standard")
  77. theme String @default("light")
  78. defaultVoiceId String? @default("cherry")
  79. defaultVolume Int @default(50)
  80. autoPlayNext Boolean @default(true)
  81. wifiOnlyDownload Boolean @default(false)
  82. updatedAt DateTime @updatedAt
  83. createdAt DateTime @default(now())
  84. user User @relation(fields: [userId], references: [id])
  85. }
  86. model Favorite {
  87. id Int @id @default(autoincrement())
  88. userId Int
  89. bookId Int
  90. createdAt DateTime @default(now())
  91. book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
  92. user User @relation(fields: [userId], references: [id])
  93. @@unique([userId, bookId])
  94. @@index([userId])
  95. @@index([bookId])
  96. }
  97. model Comment {
  98. id Int @id @default(autoincrement())
  99. userId Int
  100. chapterId Int
  101. content String @db.Text
  102. rating Int
  103. createdAt DateTime @default(now())
  104. chapter BookChapter @relation(fields: [chapterId], references: [id])
  105. user User @relation(fields: [userId], references: [id])
  106. @@index([chapterId])
  107. @@index([userId])
  108. }
  109. model Notification {
  110. id String @id @default(uuid())
  111. userId Int
  112. title String
  113. content String @db.Text
  114. isRead Boolean @default(false)
  115. createdAt DateTime @default(now())
  116. user User @relation(fields: [userId], references: [id])
  117. @@index([userId])
  118. }
  119. model Book {
  120. id Int @id @default(autoincrement())
  121. userId Int?
  122. title String
  123. subtitle String?
  124. description String @db.Text
  125. coverUrl String?
  126. targetAudience String @default("通用")
  127. style String @default("专业严谨")
  128. bookScale String @default("标准教程")
  129. totalChapters Int @default(10)
  130. estimatedWords Int @default(0)
  131. progress Int @default(0)
  132. isPublished Boolean @default(false)
  133. outlineJson String? @db.LongText
  134. foreword String? @db.Text
  135. afterword String? @db.Text
  136. errorMsg String? @db.Text
  137. createdAt DateTime @default(now())
  138. updatedAt DateTime @updatedAt
  139. failedStage String? @db.VarChar(30)
  140. genStage String @default("draft")
  141. bookAnalysis String? @db.Text
  142. chapters BookChapter[]
  143. favorites Favorite[]
  144. videoProjects VideoProject[]
  145. @@index([userId])
  146. @@index([createdAt])
  147. }
  148. model BookChapter {
  149. id Int @id @default(autoincrement())
  150. bookId Int
  151. parentId Int @default(0)
  152. level Int @default(1)
  153. number Int
  154. title String
  155. summary String? @db.Text
  156. keyPoints String? @db.Text
  157. estimatedWords Int @default(1000)
  158. content String? @db.LongText
  159. wordCount Int @default(0)
  160. contentError String? @db.Text
  161. generatedAt DateTime?
  162. audioUrl String? @db.Text
  163. audioDuration Int @default(0)
  164. videoUrl String? @db.Text
  165. videoDuration Int?
  166. isPublic Boolean @default(false)
  167. genStage String @default("idle")
  168. lrcLyrics String? @db.Text
  169. book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
  170. comments Comment[]
  171. playRecords PlayRecord[]
  172. playlistItems PlaylistItem[]
  173. videoProjects VideoProject[]
  174. @@unique([bookId, parentId, level, number])
  175. @@index([bookId])
  176. @@index([bookId, parentId])
  177. @@index([bookId, level])
  178. }
  179. model VideoProject {
  180. id Int @id @default(autoincrement())
  181. userId Int?
  182. title String
  183. description String?
  184. coverUrl String?
  185. configJson String? @db.LongText
  186. outputUrl String?
  187. duration Int?
  188. fileSize Int?
  189. bookId Int?
  190. chapterId Int?
  191. status String @default("draft")
  192. progress Int @default(0)
  193. errorMsg String? @db.Text
  194. createdAt DateTime @default(now())
  195. updatedAt DateTime @updatedAt
  196. book Book? @relation(fields: [bookId], references: [id])
  197. chapter BookChapter? @relation(fields: [chapterId], references: [id])
  198. @@index([userId, status])
  199. @@index([createdAt])
  200. @@index([bookId], map: "VideoProject_bookId_fkey")
  201. @@index([chapterId], map: "VideoProject_chapterId_fkey")
  202. }
  203. model SearchHistory {
  204. id Int @id @default(autoincrement())
  205. userId Int
  206. keyword String
  207. createdAt DateTime @default(now())
  208. @@index([userId, createdAt])
  209. @@index([userId])
  210. }
  211. model HotSearch {
  212. id Int @id @default(autoincrement())
  213. keyword String
  214. count Int @default(0)
  215. sort Int @default(0)
  216. createdAt DateTime @default(now())
  217. updatedAt DateTime @updatedAt
  218. @@index([sort])
  219. @@index([count])
  220. }
  221. model SignRecord {
  222. id Int @id @default(autoincrement())
  223. userId Int
  224. createdAt DateTime @default(now())
  225. user User @relation(fields: [userId], references: [id])
  226. @@unique([userId, createdAt])
  227. @@index([userId, createdAt])
  228. }
  229. model SubscriptionPlan {
  230. id Int @id @default(autoincrement())
  231. name String
  232. level Int @default(0)
  233. priceMonthly Decimal @default(0.00) @db.Decimal(10, 2)
  234. priceYearly Decimal @default(0.00) @db.Decimal(10, 2)
  235. description String? @db.Text
  236. features String? @db.Text
  237. isRecommended Boolean @default(false)
  238. isActive Boolean @default(true)
  239. sortOrder Int @default(0)
  240. dailyGenerations Int @default(3)
  241. perGenerationLimit Int @default(2000)
  242. monthlyTokens Int @default(10000)
  243. monthlyMinutes Int @default(30)
  244. yearlyTokens Int?
  245. voiceOptions Int @default(5)
  246. audioQuality String @default("standard")
  247. apiAccess Boolean @default(false)
  248. batchProcessing Boolean @default(false)
  249. teamManagement Boolean @default(false)
  250. overageEnabled Boolean @default(false)
  251. overagePrice Decimal @default(0.00) @db.Decimal(10, 2)
  252. createdAt DateTime @default(now())
  253. updatedAt DateTime @updatedAt
  254. orders Order[]
  255. subscriptions Subscription[]
  256. @@index([level])
  257. @@index([isActive, sortOrder])
  258. }
  259. model Subscription {
  260. id Int @id @default(autoincrement())
  261. userId Int
  262. planId Int
  263. startDate DateTime
  264. endDate DateTime
  265. status String @default("active")
  266. autoRenew Boolean @default(false)
  267. createdAt DateTime @default(now())
  268. updatedAt DateTime @updatedAt
  269. plan SubscriptionPlan @relation(fields: [planId], references: [id])
  270. user User @relation(fields: [userId], references: [id])
  271. @@index([userId, status])
  272. @@index([userId, endDate])
  273. @@index([planId], map: "Subscription_planId_fkey")
  274. }
  275. model TokenUsage {
  276. id Int @id @default(autoincrement())
  277. userId Int
  278. type String
  279. amount Int @default(0)
  280. contentLength Int @default(0)
  281. orderId Int?
  282. description String? @db.Text
  283. createdAt DateTime @default(now())
  284. order Order? @relation(fields: [orderId], references: [id])
  285. user User @relation(fields: [userId], references: [id])
  286. @@index([userId, createdAt])
  287. @@index([userId, type])
  288. @@index([orderId], map: "TokenUsage_orderId_fkey")
  289. }
  290. model TokenBalance {
  291. id Int @id @default(autoincrement())
  292. userId Int @unique
  293. totalTokens Int @default(0)
  294. usedTokens Int @default(0)
  295. resetDate DateTime?
  296. createdAt DateTime @default(now())
  297. updatedAt DateTime @updatedAt
  298. user User @relation(fields: [userId], references: [id])
  299. @@index([userId])
  300. }
  301. model VideoMaterial {
  302. id Int @id @default(autoincrement())
  303. userId Int?
  304. type String
  305. name String
  306. url String @db.Text
  307. thumbnail String?
  308. tags String? @db.Text
  309. category String?
  310. duration Int?
  311. size Int?
  312. width Int?
  313. height Int?
  314. createdAt DateTime @default(now())
  315. updatedAt DateTime @updatedAt
  316. @@index([userId, type])
  317. @@index([type, category])
  318. }
  319. model AudioRecord {
  320. id Int @id @default(autoincrement())
  321. userId Int?
  322. audioId String @unique
  323. title String @default("未命名音频")
  324. text String? @db.LongText
  325. wordCount Int @default(0)
  326. voiceId String @default("cherry")
  327. voiceParams String?
  328. audioUrl String? @db.Text
  329. audioDuration Int @default(0)
  330. audioSize Int @default(0)
  331. status String @default("processing")
  332. errorMsg String? @db.Text
  333. createdAt DateTime @default(now())
  334. updatedAt DateTime @updatedAt
  335. bookId Int?
  336. @@index([userId])
  337. @@index([audioId])
  338. @@index([bookId])
  339. }
  340. model PlatformAccount {
  341. id Int @id @default(autoincrement())
  342. userId Int
  343. platform String
  344. nickname String @default("")
  345. avatar String @default("")
  346. cookies String @db.Text
  347. headers String? @db.Text
  348. isValid Boolean @default(true)
  349. expireTime DateTime?
  350. createdAt DateTime @default(now())
  351. updatedAt DateTime @updatedAt
  352. @@unique([userId, platform])
  353. @@index([userId])
  354. @@index([platform])
  355. }
  356. model PublishTask {
  357. id Int @id @default(autoincrement())
  358. userId Int
  359. videoProjectId Int
  360. platform String
  361. title String @db.Text
  362. description String? @db.Text
  363. tags String? @db.Text
  364. coverUrl String? @db.Text
  365. videoUrl String? @db.Text
  366. status String @default("pending")
  367. errorMsg String? @db.Text
  368. publishedUrl String? @db.Text
  369. createdAt DateTime @default(now())
  370. updatedAt DateTime @updatedAt
  371. @@index([userId, platform])
  372. @@index([status])
  373. }
  374. model Draft {
  375. id Int @id @default(autoincrement())
  376. userId Int
  377. type String
  378. title String? @db.Text
  379. content String? @db.LongText
  380. metadata String? @db.Text
  381. autoSavedAt DateTime?
  382. createdAt DateTime @default(now())
  383. updatedAt DateTime @updatedAt
  384. user User @relation(fields: [userId], references: [id])
  385. @@index([userId, type])
  386. @@index([userId, updatedAt])
  387. }
  388. model Playlist {
  389. id Int @id @default(autoincrement())
  390. userId Int
  391. name String
  392. description String? @db.Text
  393. createdAt DateTime @default(now())
  394. updatedAt DateTime @updatedAt
  395. user User @relation(fields: [userId], references: [id])
  396. items PlaylistItem[]
  397. @@index([userId])
  398. }
  399. model PlaylistItem {
  400. id Int @id @default(autoincrement())
  401. playlistId Int
  402. chapterId Int?
  403. audioId String?
  404. order Int @default(0)
  405. chapter BookChapter? @relation(fields: [chapterId], references: [id])
  406. playlist Playlist @relation(fields: [playlistId], references: [id], onDelete: Cascade)
  407. @@index([playlistId, order])
  408. @@index([chapterId], map: "PlaylistItem_chapterId_fkey")
  409. }
  410. model Feedback {
  411. id String @id @default(uuid())
  412. type String
  413. title String @db.Text
  414. content String @db.Text
  415. contact String @db.Text
  416. screenshotUrls String @db.Text
  417. status String @default("submitted")
  418. createdAt DateTime @default(now())
  419. updatedAt DateTime @updatedAt
  420. @@index([type])
  421. @@index([status])
  422. @@index([createdAt])
  423. }