schema.prisma 14 KB

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