schema.prisma 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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. costLimit Float @default(0)
  22. quotaReserved Float @default(0)
  23. subscriptionResetDate DateTime?
  24. comments Comment[]
  25. drafts Draft[]
  26. favorites Favorite[]
  27. notifications Notification[]
  28. orders Order[]
  29. playRecords PlayRecord[]
  30. playlists Playlist[]
  31. signRecords SignRecord[]
  32. subscriptions Subscription[]
  33. tokenBalance TokenBalance?
  34. tokenUsages TokenUsage[]
  35. preferences UserPreference?
  36. shareRecords ShareRecord[]
  37. invitesSent InviteRecord[] @relation("InviterRelation")
  38. invitesReceived InviteRecord[] @relation("InviteeRelation")
  39. @@index([phone])
  40. @@index([openid])
  41. }
  42. model Order {
  43. id Int @id @default(autoincrement())
  44. userId Int
  45. orderNo String @unique
  46. planId Int?
  47. productType String
  48. amount Decimal @db.Decimal(10, 2)
  49. status String @default("pending")
  50. paymentMethod String?
  51. paymentId String?
  52. paidAt DateTime?
  53. createdAt DateTime @default(now())
  54. updatedAt DateTime @updatedAt
  55. plan SubscriptionPlan? @relation(fields: [planId], references: [id])
  56. user User @relation(fields: [userId], references: [id])
  57. tokenUsages TokenUsage[]
  58. @@index([userId, createdAt])
  59. @@index([orderNo])
  60. @@index([status])
  61. @@index([planId], map: "Order_planId_fkey")
  62. }
  63. model PlayRecord {
  64. id Int @id @default(autoincrement())
  65. userId Int
  66. chapterId Int
  67. progress Float @default(0)
  68. duration Float @default(0)
  69. updatedAt DateTime @updatedAt
  70. createdAt DateTime @default(now())
  71. chapter BookChapter @relation(fields: [chapterId], references: [id])
  72. user User @relation(fields: [userId], references: [id])
  73. @@unique([userId, chapterId])
  74. @@index([userId])
  75. @@index([chapterId])
  76. }
  77. model UserPreference {
  78. id Int @id @default(autoincrement())
  79. userId Int @unique
  80. playSpeed Float @default(1)
  81. quality String @default("standard")
  82. theme String @default("light")
  83. defaultVoiceId String? @default("cherry")
  84. defaultVolume Int @default(50)
  85. autoPlayNext Boolean @default(true)
  86. wifiOnlyDownload Boolean @default(false)
  87. updatedAt DateTime @updatedAt
  88. createdAt DateTime @default(now())
  89. user User @relation(fields: [userId], references: [id])
  90. }
  91. model Favorite {
  92. id Int @id @default(autoincrement())
  93. userId Int
  94. bookId Int
  95. createdAt DateTime @default(now())
  96. book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
  97. user User @relation(fields: [userId], references: [id])
  98. @@unique([userId, bookId])
  99. @@index([userId])
  100. @@index([bookId])
  101. }
  102. model Comment {
  103. id Int @id @default(autoincrement())
  104. userId Int
  105. chapterId Int
  106. content String @db.Text
  107. rating Int
  108. createdAt DateTime @default(now())
  109. chapter BookChapter @relation(fields: [chapterId], references: [id])
  110. user User @relation(fields: [userId], references: [id])
  111. @@index([chapterId])
  112. @@index([userId])
  113. }
  114. model Notification {
  115. id String @id @default(uuid())
  116. userId Int
  117. title String
  118. content String @db.Text
  119. isRead Boolean @default(false)
  120. createdAt DateTime @default(now())
  121. user User @relation(fields: [userId], references: [id])
  122. @@index([userId])
  123. }
  124. model Book {
  125. id Int @id @default(autoincrement())
  126. userId Int?
  127. title String
  128. subtitle String?
  129. description String @db.Text
  130. coverUrl String?
  131. targetAudience String @default("通用")
  132. style String @default("专业严谨")
  133. bookScale String @default("1000")
  134. totalChapters Int @default(10)
  135. estimatedWords Int @default(0)
  136. progress Int @default(0)
  137. isPublished Boolean @default(false)
  138. outlineJson String? @db.LongText
  139. foreword String? @db.Text
  140. afterword String? @db.Text
  141. errorMsg String? @db.Text
  142. voiceSpeed Float @default(1.0)
  143. createdAt DateTime @default(now())
  144. updatedAt DateTime @updatedAt
  145. failedStage String? @db.VarChar(30)
  146. genStage String @default("draft")
  147. bookAnalysis String? @db.Text
  148. autoGenerateContent Boolean @default(true)
  149. autoGenerateAudio Boolean @default(true)
  150. chapters BookChapter[]
  151. favorites Favorite[]
  152. videoProjects VideoProject[]
  153. @@index([userId])
  154. @@index([createdAt])
  155. }
  156. model BookChapter {
  157. id Int @id @default(autoincrement())
  158. bookId Int
  159. parentId Int @default(0)
  160. level Int @default(1)
  161. number Int
  162. title String
  163. summary String? @db.Text
  164. keyPoints String? @db.Text
  165. estimatedWords Int @default(1000)
  166. content String? @db.LongText
  167. wordCount Int @default(0)
  168. contentError String? @db.Text
  169. generatedAt DateTime?
  170. audioUrl String? @db.Text
  171. audioDuration Int @default(0)
  172. videoUrl String? @db.Text
  173. videoDuration Int?
  174. isPublic Boolean @default(false)
  175. genStage String @default("idle")
  176. lrcLyrics String? @db.Text
  177. contentCheck String? @db.Text
  178. book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
  179. comments Comment[]
  180. playRecords PlayRecord[]
  181. playlistItems PlaylistItem[]
  182. ttsTasks TtsTask[]
  183. videoProjects VideoProject[]
  184. @@unique([bookId, parentId, level, number])
  185. @@index([bookId])
  186. @@index([bookId, parentId])
  187. @@index([bookId, level])
  188. }
  189. model VideoProject {
  190. id Int @id @default(autoincrement())
  191. userId Int?
  192. title String
  193. description String?
  194. coverUrl String?
  195. configJson String? @db.LongText
  196. outputUrl String?
  197. duration Int?
  198. fileSize Int?
  199. bookId Int?
  200. chapterId Int?
  201. status String @default("draft")
  202. progress Int @default(0)
  203. errorMsg String? @db.Text
  204. createdAt DateTime @default(now())
  205. updatedAt DateTime @updatedAt
  206. book Book? @relation(fields: [bookId], references: [id])
  207. chapter BookChapter? @relation(fields: [chapterId], references: [id])
  208. @@index([userId, status])
  209. @@index([createdAt])
  210. @@index([bookId], map: "VideoProject_bookId_fkey")
  211. @@index([chapterId], map: "VideoProject_chapterId_fkey")
  212. }
  213. model SearchHistory {
  214. id Int @id @default(autoincrement())
  215. userId Int
  216. keyword String
  217. createdAt DateTime @default(now())
  218. @@index([userId, createdAt])
  219. @@index([userId])
  220. }
  221. model HotSearch {
  222. id Int @id @default(autoincrement())
  223. keyword String
  224. count Int @default(0)
  225. sort Int @default(0)
  226. createdAt DateTime @default(now())
  227. updatedAt DateTime @updatedAt
  228. @@index([sort])
  229. @@index([count])
  230. }
  231. model SignRecord {
  232. id Int @id @default(autoincrement())
  233. userId Int
  234. createdAt DateTime @default(now())
  235. user User @relation(fields: [userId], references: [id])
  236. @@unique([userId, createdAt])
  237. @@index([userId, createdAt])
  238. }
  239. model SubscriptionPlan {
  240. id Int @id @default(autoincrement())
  241. name String
  242. level Int @default(0)
  243. priceMonthly Decimal @default(0.00) @db.Decimal(10, 2)
  244. priceYearly Decimal @default(0.00) @db.Decimal(10, 2)
  245. description String? @db.Text
  246. features String? @db.Text
  247. isRecommended Boolean @default(false)
  248. isActive Boolean @default(true)
  249. sortOrder Int @default(0)
  250. dailyGenerations Int @default(3)
  251. perGenerationLimit Int @default(2000)
  252. monthlyTokens Int @default(10000)
  253. monthlyMinutes Int @default(30)
  254. yearlyTokens Int?
  255. voiceOptions Int @default(5)
  256. audioQuality String @default("standard")
  257. apiAccess Boolean @default(false)
  258. batchProcessing Boolean @default(false)
  259. teamManagement Boolean @default(false)
  260. overageEnabled Boolean @default(false)
  261. overagePrice Decimal @default(0.000) @db.Decimal(10, 3)
  262. createdAt DateTime @default(now())
  263. updatedAt DateTime @updatedAt
  264. orders Order[]
  265. subscriptions Subscription[]
  266. @@index([level])
  267. @@index([isActive, sortOrder])
  268. }
  269. model Subscription {
  270. id Int @id @default(autoincrement())
  271. userId Int
  272. planId Int
  273. startDate DateTime
  274. endDate DateTime
  275. status String @default("active")
  276. autoRenew Boolean @default(false)
  277. createdAt DateTime @default(now())
  278. updatedAt DateTime @updatedAt
  279. plan SubscriptionPlan @relation(fields: [planId], references: [id])
  280. user User @relation(fields: [userId], references: [id])
  281. @@index([userId, status])
  282. @@index([userId, endDate])
  283. @@index([planId], map: "Subscription_planId_fkey")
  284. }
  285. model TokenUsage {
  286. id Int @id @default(autoincrement())
  287. userId Int
  288. type String
  289. amount Int @default(0)
  290. contentLength Int @default(0)
  291. orderId Int?
  292. description String? @db.Text
  293. createdAt DateTime @default(now())
  294. order Order? @relation(fields: [orderId], references: [id])
  295. user User @relation(fields: [userId], references: [id])
  296. @@index([userId, createdAt])
  297. @@index([userId, type])
  298. @@index([orderId], map: "TokenUsage_orderId_fkey")
  299. }
  300. model TokenBalance {
  301. id Int @id @default(autoincrement())
  302. userId Int @unique
  303. totalTokens Int @default(0)
  304. usedTokens Int @default(0) // 总消耗
  305. packTokens Int @default(0) // 积分包购买的Token总数
  306. usedPackTokens Int @default(0) // 积分包已消耗的Token数
  307. resetDate DateTime?
  308. createdAt DateTime @default(now())
  309. updatedAt DateTime @updatedAt
  310. user User @relation(fields: [userId], references: [id])
  311. @@index([userId])
  312. }
  313. model VideoMaterial {
  314. id Int @id @default(autoincrement())
  315. userId Int?
  316. type String
  317. name String
  318. url String @db.Text
  319. thumbnail String?
  320. tags String? @db.Text
  321. category String?
  322. duration Int?
  323. size Int?
  324. width Int?
  325. height Int?
  326. createdAt DateTime @default(now())
  327. updatedAt DateTime @updatedAt
  328. @@index([userId, type])
  329. @@index([type, category])
  330. }
  331. model AudioRecord {
  332. id Int @id @default(autoincrement())
  333. userId Int?
  334. audioId String @unique
  335. title String @default("未命名音频")
  336. text String? @db.LongText
  337. wordCount Int @default(0)
  338. voiceId String @default("cherry")
  339. voiceParams String?
  340. audioUrl String? @db.Text
  341. audioDuration Int @default(0)
  342. audioSize Int @default(0)
  343. status String @default("processing")
  344. errorMsg String? @db.Text
  345. createdAt DateTime @default(now())
  346. updatedAt DateTime @updatedAt
  347. bookId Int?
  348. provider String? // TTS 供应商: bailian / edge / mock
  349. @@index([userId])
  350. @@index([audioId])
  351. @@index([bookId])
  352. }
  353. model TtsTask {
  354. id Int @id @default(autoincrement())
  355. taskType String @default("tts") @db.VarChar(20) // "tts" | "content"
  356. chapterId Int
  357. bookId Int?
  358. userId Int?
  359. contentHash String @db.VarChar(64)
  360. content String? @db.LongText
  361. status String @default("pending")
  362. audioUrl String? @db.Text
  363. audioDuration Int @default(0)
  364. errorMsg String? @db.Text
  365. retryCount Int @default(0)
  366. maxRetries Int @default(3)
  367. voiceId String @default("default")
  368. voiceSpeed Float @default(1.0)
  369. startedAt DateTime?
  370. completedAt DateTime?
  371. createdAt DateTime @default(now())
  372. updatedAt DateTime @updatedAt
  373. chapter BookChapter @relation(fields: [chapterId], references: [id], onDelete: Cascade)
  374. @@index([taskType, status, createdAt])
  375. @@index([chapterId, contentHash])
  376. @@index([contentHash, chapterId])
  377. }
  378. model AiCallLog {
  379. id Int @id @default(autoincrement())
  380. callType String @db.VarChar(20) // llm_chat | llm_tools | tts_synthesize | tts_create | tts_poll
  381. provider String @db.VarChar(30) // minimax | bailian | volcengine
  382. model String @db.VarChar(50) // MiniMax-M2.7 | cosyvoice-v3-flash | qwen3-tts-instruct-flash
  383. userId Int?
  384. bookId Int?
  385. chapterId Int?
  386. textLen Int @default(0) // 输入文本长度(字符数)
  387. prompt String? @db.LongText // 提示词内容(LLM only)
  388. inputTokens Int @default(0) // 输入 Token 数
  389. outputTokens Int @default(0) // 输出 Token 数
  390. estimatedCost Float @default(0) // 估算成本(元)
  391. duration Int @default(0) // 耗时(ms)
  392. success Boolean @default(true)
  393. errorMsg String? @db.Text
  394. createdAt DateTime @default(now())
  395. @@index([callType, createdAt])
  396. @@index([provider, createdAt])
  397. @@index([userId, createdAt])
  398. @@index([bookId])
  399. @@index([createdAt])
  400. }
  401. model PlatformAccount {
  402. id Int @id @default(autoincrement())
  403. userId Int
  404. platform String
  405. nickname String @default("")
  406. avatar String @default("")
  407. cookies String @db.Text
  408. headers String? @db.Text
  409. isValid Boolean @default(true)
  410. expireTime DateTime?
  411. createdAt DateTime @default(now())
  412. updatedAt DateTime @updatedAt
  413. @@unique([userId, platform])
  414. @@index([userId])
  415. @@index([platform])
  416. }
  417. model PublishTask {
  418. id Int @id @default(autoincrement())
  419. userId Int
  420. videoProjectId Int
  421. platform String
  422. title String @db.Text
  423. description String? @db.Text
  424. tags String? @db.Text
  425. coverUrl String? @db.Text
  426. videoUrl String? @db.Text
  427. status String @default("pending")
  428. errorMsg String? @db.Text
  429. publishedUrl String? @db.Text
  430. createdAt DateTime @default(now())
  431. updatedAt DateTime @updatedAt
  432. @@index([userId, platform])
  433. @@index([status])
  434. }
  435. model Draft {
  436. id Int @id @default(autoincrement())
  437. userId Int
  438. type String
  439. title String? @db.Text
  440. content String? @db.LongText
  441. metadata String? @db.Text
  442. autoSavedAt DateTime?
  443. createdAt DateTime @default(now())
  444. updatedAt DateTime @updatedAt
  445. user User @relation(fields: [userId], references: [id])
  446. @@index([userId, type])
  447. @@index([userId, updatedAt])
  448. }
  449. model Playlist {
  450. id Int @id @default(autoincrement())
  451. userId Int
  452. name String
  453. description String? @db.Text
  454. createdAt DateTime @default(now())
  455. updatedAt DateTime @updatedAt
  456. user User @relation(fields: [userId], references: [id])
  457. items PlaylistItem[]
  458. @@index([userId])
  459. }
  460. model PlaylistItem {
  461. id Int @id @default(autoincrement())
  462. playlistId Int
  463. chapterId Int?
  464. audioId String?
  465. order Int @default(0)
  466. chapter BookChapter? @relation(fields: [chapterId], references: [id])
  467. playlist Playlist @relation(fields: [playlistId], references: [id], onDelete: Cascade)
  468. @@index([playlistId, order])
  469. @@index([chapterId], map: "PlaylistItem_chapterId_fkey")
  470. }
  471. model Feedback {
  472. id String @id @default(uuid())
  473. type String
  474. title String @db.Text
  475. content String @db.Text
  476. contact String @db.Text
  477. screenshotUrls String @db.Text
  478. status String @default("submitted")
  479. createdAt DateTime @default(now())
  480. updatedAt DateTime @updatedAt
  481. @@index([type])
  482. @@index([status])
  483. @@index([createdAt])
  484. }
  485. model ShareRecord {
  486. id Int @id @default(autoincrement())
  487. userId Int
  488. audioId Int
  489. platform String
  490. shareCode String
  491. rewarded Boolean @default(false)
  492. createdAt DateTime @default(now())
  493. user User @relation(fields: [userId], references: [id])
  494. @@index([userId])
  495. @@index([shareCode])
  496. @@index([createdAt])
  497. }
  498. model InviteRecord {
  499. id Int @id @default(autoincrement())
  500. inviterId Int
  501. inviteeId Int @unique
  502. shareCode String?
  503. rewarded Boolean @default(false)
  504. rewardAmount Int @default(10000)
  505. createdAt DateTime @default(now())
  506. inviter User @relation("InviterRelation", fields: [inviterId], references: [id])
  507. invitee User @relation("InviteeRelation", fields: [inviteeId], references: [id])
  508. @@index([inviterId])
  509. @@index([shareCode])
  510. }
  511. model TokenPackPurchase {
  512. id Int @id @default(autoincrement())
  513. userId Int
  514. packMinutes Int
  515. quantity Int
  516. unitPrice Float
  517. totalAmount Float
  518. addedQuota Float
  519. createdAt DateTime @default(now())
  520. }