schema.prisma 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. createdAt DateTime @default(now())
  143. updatedAt DateTime @updatedAt
  144. failedStage String? @db.VarChar(30)
  145. genStage String @default("draft")
  146. bookAnalysis String? @db.Text
  147. chapters BookChapter[]
  148. favorites Favorite[]
  149. videoProjects VideoProject[]
  150. @@index([userId])
  151. @@index([createdAt])
  152. }
  153. model BookChapter {
  154. id Int @id @default(autoincrement())
  155. bookId Int
  156. parentId Int @default(0)
  157. level Int @default(1)
  158. number Int
  159. title String
  160. summary String? @db.Text
  161. keyPoints String? @db.Text
  162. estimatedWords Int @default(1000)
  163. content String? @db.LongText
  164. wordCount Int @default(0)
  165. contentError String? @db.Text
  166. generatedAt DateTime?
  167. audioUrl String? @db.Text
  168. audioDuration Int @default(0)
  169. videoUrl String? @db.Text
  170. videoDuration Int?
  171. isPublic Boolean @default(false)
  172. genStage String @default("idle")
  173. lrcLyrics String? @db.Text
  174. contentCheck String? @db.Text
  175. book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
  176. comments Comment[]
  177. playRecords PlayRecord[]
  178. playlistItems PlaylistItem[]
  179. ttsTasks TtsTask[]
  180. videoProjects VideoProject[]
  181. @@unique([bookId, parentId, level, number])
  182. @@index([bookId])
  183. @@index([bookId, parentId])
  184. @@index([bookId, level])
  185. }
  186. model VideoProject {
  187. id Int @id @default(autoincrement())
  188. userId Int?
  189. title String
  190. description String?
  191. coverUrl String?
  192. configJson String? @db.LongText
  193. outputUrl String?
  194. duration Int?
  195. fileSize Int?
  196. bookId Int?
  197. chapterId Int?
  198. status String @default("draft")
  199. progress Int @default(0)
  200. errorMsg String? @db.Text
  201. createdAt DateTime @default(now())
  202. updatedAt DateTime @updatedAt
  203. book Book? @relation(fields: [bookId], references: [id])
  204. chapter BookChapter? @relation(fields: [chapterId], references: [id])
  205. @@index([userId, status])
  206. @@index([createdAt])
  207. @@index([bookId], map: "VideoProject_bookId_fkey")
  208. @@index([chapterId], map: "VideoProject_chapterId_fkey")
  209. }
  210. model SearchHistory {
  211. id Int @id @default(autoincrement())
  212. userId Int
  213. keyword String
  214. createdAt DateTime @default(now())
  215. @@index([userId, createdAt])
  216. @@index([userId])
  217. }
  218. model HotSearch {
  219. id Int @id @default(autoincrement())
  220. keyword String
  221. count Int @default(0)
  222. sort Int @default(0)
  223. createdAt DateTime @default(now())
  224. updatedAt DateTime @updatedAt
  225. @@index([sort])
  226. @@index([count])
  227. }
  228. model SignRecord {
  229. id Int @id @default(autoincrement())
  230. userId Int
  231. createdAt DateTime @default(now())
  232. user User @relation(fields: [userId], references: [id])
  233. @@unique([userId, createdAt])
  234. @@index([userId, createdAt])
  235. }
  236. model SubscriptionPlan {
  237. id Int @id @default(autoincrement())
  238. name String
  239. level Int @default(0)
  240. priceMonthly Decimal @default(0.00) @db.Decimal(10, 2)
  241. priceYearly Decimal @default(0.00) @db.Decimal(10, 2)
  242. description String? @db.Text
  243. features String? @db.Text
  244. isRecommended Boolean @default(false)
  245. isActive Boolean @default(true)
  246. sortOrder Int @default(0)
  247. dailyGenerations Int @default(3)
  248. perGenerationLimit Int @default(2000)
  249. monthlyTokens Int @default(10000)
  250. monthlyMinutes Int @default(30)
  251. yearlyTokens Int?
  252. voiceOptions Int @default(5)
  253. audioQuality String @default("standard")
  254. apiAccess Boolean @default(false)
  255. batchProcessing Boolean @default(false)
  256. teamManagement Boolean @default(false)
  257. overageEnabled Boolean @default(false)
  258. overagePrice Decimal @default(0.00) @db.Decimal(10, 2)
  259. createdAt DateTime @default(now())
  260. updatedAt DateTime @updatedAt
  261. orders Order[]
  262. subscriptions Subscription[]
  263. @@index([level])
  264. @@index([isActive, sortOrder])
  265. }
  266. model Subscription {
  267. id Int @id @default(autoincrement())
  268. userId Int
  269. planId Int
  270. startDate DateTime
  271. endDate DateTime
  272. status String @default("active")
  273. autoRenew Boolean @default(false)
  274. createdAt DateTime @default(now())
  275. updatedAt DateTime @updatedAt
  276. plan SubscriptionPlan @relation(fields: [planId], references: [id])
  277. user User @relation(fields: [userId], references: [id])
  278. @@index([userId, status])
  279. @@index([userId, endDate])
  280. @@index([planId], map: "Subscription_planId_fkey")
  281. }
  282. model TokenUsage {
  283. id Int @id @default(autoincrement())
  284. userId Int
  285. type String
  286. amount Int @default(0)
  287. contentLength Int @default(0)
  288. orderId Int?
  289. description String? @db.Text
  290. createdAt DateTime @default(now())
  291. order Order? @relation(fields: [orderId], references: [id])
  292. user User @relation(fields: [userId], references: [id])
  293. @@index([userId, createdAt])
  294. @@index([userId, type])
  295. @@index([orderId], map: "TokenUsage_orderId_fkey")
  296. }
  297. model TokenBalance {
  298. id Int @id @default(autoincrement())
  299. userId Int @unique
  300. totalTokens Int @default(0)
  301. usedTokens Int @default(0)
  302. resetDate DateTime?
  303. createdAt DateTime @default(now())
  304. updatedAt DateTime @updatedAt
  305. user User @relation(fields: [userId], references: [id])
  306. @@index([userId])
  307. }
  308. model VideoMaterial {
  309. id Int @id @default(autoincrement())
  310. userId Int?
  311. type String
  312. name String
  313. url String @db.Text
  314. thumbnail String?
  315. tags String? @db.Text
  316. category String?
  317. duration Int?
  318. size Int?
  319. width Int?
  320. height Int?
  321. createdAt DateTime @default(now())
  322. updatedAt DateTime @updatedAt
  323. @@index([userId, type])
  324. @@index([type, category])
  325. }
  326. model AudioRecord {
  327. id Int @id @default(autoincrement())
  328. userId Int?
  329. audioId String @unique
  330. title String @default("未命名音频")
  331. text String? @db.LongText
  332. wordCount Int @default(0)
  333. voiceId String @default("cherry")
  334. voiceParams String?
  335. audioUrl String? @db.Text
  336. audioDuration Int @default(0)
  337. audioSize Int @default(0)
  338. status String @default("processing")
  339. errorMsg String? @db.Text
  340. createdAt DateTime @default(now())
  341. updatedAt DateTime @updatedAt
  342. bookId Int?
  343. @@index([userId])
  344. @@index([audioId])
  345. @@index([bookId])
  346. }
  347. model TtsTask {
  348. id Int @id @default(autoincrement())
  349. taskType String @default("tts") @db.VarChar(20) // "tts" | "content"
  350. chapterId Int
  351. bookId Int?
  352. userId Int?
  353. contentHash String @db.VarChar(64)
  354. content String? @db.LongText
  355. status String @default("pending")
  356. audioUrl String? @db.Text
  357. audioDuration Int @default(0)
  358. errorMsg String? @db.Text
  359. retryCount Int @default(0)
  360. maxRetries Int @default(3)
  361. voiceId String @default("default")
  362. startedAt DateTime?
  363. completedAt DateTime?
  364. createdAt DateTime @default(now())
  365. updatedAt DateTime @updatedAt
  366. chapter BookChapter @relation(fields: [chapterId], references: [id], onDelete: Cascade)
  367. @@index([taskType, status, createdAt])
  368. @@index([chapterId, contentHash])
  369. @@index([contentHash, chapterId])
  370. }
  371. model AiCallLog {
  372. id Int @id @default(autoincrement())
  373. callType String @db.VarChar(20) // llm_chat | llm_tools | tts_synthesize | tts_create | tts_poll
  374. provider String @db.VarChar(30) // minimax | bailian | volcengine
  375. model String @db.VarChar(50) // MiniMax-M2.7 | cosyvoice-v3-flash | qwen3-tts-instruct-flash
  376. userId Int?
  377. bookId Int?
  378. chapterId Int?
  379. textLen Int @default(0) // 输入文本长度(字符数)
  380. prompt String? @db.LongText // 提示词内容(LLM only)
  381. inputTokens Int @default(0) // 输入 Token 数
  382. outputTokens Int @default(0) // 输出 Token 数
  383. estimatedCost Float @default(0) // 估算成本(元)
  384. duration Int @default(0) // 耗时(ms)
  385. success Boolean @default(true)
  386. errorMsg String? @db.Text
  387. createdAt DateTime @default(now())
  388. @@index([callType, createdAt])
  389. @@index([provider, createdAt])
  390. @@index([userId, createdAt])
  391. @@index([bookId])
  392. @@index([createdAt])
  393. }
  394. model PlatformAccount {
  395. id Int @id @default(autoincrement())
  396. userId Int
  397. platform String
  398. nickname String @default("")
  399. avatar String @default("")
  400. cookies String @db.Text
  401. headers String? @db.Text
  402. isValid Boolean @default(true)
  403. expireTime DateTime?
  404. createdAt DateTime @default(now())
  405. updatedAt DateTime @updatedAt
  406. @@unique([userId, platform])
  407. @@index([userId])
  408. @@index([platform])
  409. }
  410. model PublishTask {
  411. id Int @id @default(autoincrement())
  412. userId Int
  413. videoProjectId Int
  414. platform String
  415. title String @db.Text
  416. description String? @db.Text
  417. tags String? @db.Text
  418. coverUrl String? @db.Text
  419. videoUrl String? @db.Text
  420. status String @default("pending")
  421. errorMsg String? @db.Text
  422. publishedUrl String? @db.Text
  423. createdAt DateTime @default(now())
  424. updatedAt DateTime @updatedAt
  425. @@index([userId, platform])
  426. @@index([status])
  427. }
  428. model Draft {
  429. id Int @id @default(autoincrement())
  430. userId Int
  431. type String
  432. title String? @db.Text
  433. content String? @db.LongText
  434. metadata String? @db.Text
  435. autoSavedAt DateTime?
  436. createdAt DateTime @default(now())
  437. updatedAt DateTime @updatedAt
  438. user User @relation(fields: [userId], references: [id])
  439. @@index([userId, type])
  440. @@index([userId, updatedAt])
  441. }
  442. model Playlist {
  443. id Int @id @default(autoincrement())
  444. userId Int
  445. name String
  446. description String? @db.Text
  447. createdAt DateTime @default(now())
  448. updatedAt DateTime @updatedAt
  449. user User @relation(fields: [userId], references: [id])
  450. items PlaylistItem[]
  451. @@index([userId])
  452. }
  453. model PlaylistItem {
  454. id Int @id @default(autoincrement())
  455. playlistId Int
  456. chapterId Int?
  457. audioId String?
  458. order Int @default(0)
  459. chapter BookChapter? @relation(fields: [chapterId], references: [id])
  460. playlist Playlist @relation(fields: [playlistId], references: [id], onDelete: Cascade)
  461. @@index([playlistId, order])
  462. @@index([chapterId], map: "PlaylistItem_chapterId_fkey")
  463. }
  464. model Feedback {
  465. id String @id @default(uuid())
  466. type String
  467. title String @db.Text
  468. content String @db.Text
  469. contact String @db.Text
  470. screenshotUrls String @db.Text
  471. status String @default("submitted")
  472. createdAt DateTime @default(now())
  473. updatedAt DateTime @updatedAt
  474. @@index([type])
  475. @@index([status])
  476. @@index([createdAt])
  477. }
  478. model ShareRecord {
  479. id Int @id @default(autoincrement())
  480. userId Int
  481. audioId Int
  482. platform String
  483. shareCode String @unique
  484. createdAt DateTime @default(now())
  485. user User @relation(fields: [userId], references: [id])
  486. @@index([userId])
  487. @@index([shareCode])
  488. }
  489. model InviteRecord {
  490. id Int @id @default(autoincrement())
  491. inviterId Int
  492. inviteeId Int @unique
  493. shareCode String?
  494. rewarded Boolean @default(false)
  495. createdAt DateTime @default(now())
  496. inviter User @relation("InviterRelation", fields: [inviterId], references: [id])
  497. invitee User @relation("InviteeRelation", fields: [inviteeId], references: [id])
  498. @@index([inviterId])
  499. @@index([shareCode])
  500. }
  501. model TokenPackPurchase {
  502. id Int @id @default(autoincrement())
  503. userId Int
  504. packMinutes Int
  505. quantity Int
  506. unitPrice Float
  507. totalAmount Float
  508. addedQuota Float
  509. createdAt DateTime @default(now())
  510. }