schema.prisma 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. bookAnalysis String? @db.Text
  139. chapters BookChapter[]
  140. favorites Favorite[]
  141. videoProjects VideoProject[]
  142. @@index([userId])
  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. book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
  167. comments Comment[]
  168. playRecords PlayRecord[]
  169. playlistItems PlaylistItem[]
  170. videoProjects VideoProject[]
  171. @@unique([bookId, parentId, level, number])
  172. @@index([bookId])
  173. @@index([bookId, parentId])
  174. @@index([bookId, level])
  175. }
  176. model VideoProject {
  177. id Int @id @default(autoincrement())
  178. userId Int?
  179. title String
  180. description String?
  181. coverUrl String?
  182. configJson String? @db.LongText
  183. outputUrl String?
  184. duration Int?
  185. fileSize Int?
  186. bookId Int?
  187. chapterId Int?
  188. status String @default("draft")
  189. progress Int @default(0)
  190. errorMsg String? @db.Text
  191. createdAt DateTime @default(now())
  192. updatedAt DateTime @updatedAt
  193. book Book? @relation(fields: [bookId], references: [id])
  194. chapter BookChapter? @relation(fields: [chapterId], references: [id])
  195. @@index([userId, status])
  196. @@index([createdAt])
  197. @@index([bookId], map: "VideoProject_bookId_fkey")
  198. @@index([chapterId], map: "VideoProject_chapterId_fkey")
  199. }
  200. model SearchHistory {
  201. id Int @id @default(autoincrement())
  202. userId Int
  203. keyword String
  204. createdAt DateTime @default(now())
  205. @@index([userId, createdAt])
  206. @@index([userId])
  207. }
  208. model HotSearch {
  209. id Int @id @default(autoincrement())
  210. keyword String
  211. count Int @default(0)
  212. sort Int @default(0)
  213. createdAt DateTime @default(now())
  214. updatedAt DateTime @updatedAt
  215. @@index([sort])
  216. @@index([count])
  217. }
  218. model SignRecord {
  219. id Int @id @default(autoincrement())
  220. userId Int
  221. createdAt DateTime @default(now())
  222. user User @relation(fields: [userId], references: [id])
  223. @@unique([userId, createdAt])
  224. @@index([userId, createdAt])
  225. }
  226. model SubscriptionPlan {
  227. id Int @id @default(autoincrement())
  228. name String
  229. level Int @default(0)
  230. priceMonthly Decimal @default(0.00) @db.Decimal(10, 2)
  231. priceYearly Decimal @default(0.00) @db.Decimal(10, 2)
  232. description String? @db.Text
  233. features String? @db.Text
  234. isRecommended Boolean @default(false)
  235. isActive Boolean @default(true)
  236. sortOrder Int @default(0)
  237. dailyGenerations Int @default(3)
  238. perGenerationLimit Int @default(2000)
  239. monthlyTokens Int @default(10000)
  240. monthlyMinutes Int @default(30)
  241. yearlyTokens Int?
  242. voiceOptions Int @default(5)
  243. audioQuality String @default("standard")
  244. apiAccess Boolean @default(false)
  245. batchProcessing Boolean @default(false)
  246. teamManagement Boolean @default(false)
  247. overageEnabled Boolean @default(false)
  248. overagePrice Decimal @default(0.00) @db.Decimal(10, 2)
  249. createdAt DateTime @default(now())
  250. updatedAt DateTime @updatedAt
  251. orders Order[]
  252. subscriptions Subscription[]
  253. @@index([level])
  254. @@index([isActive, sortOrder])
  255. }
  256. model Subscription {
  257. id Int @id @default(autoincrement())
  258. userId Int
  259. planId Int
  260. startDate DateTime
  261. endDate DateTime
  262. status String @default("active")
  263. autoRenew Boolean @default(false)
  264. createdAt DateTime @default(now())
  265. updatedAt DateTime @updatedAt
  266. plan SubscriptionPlan @relation(fields: [planId], references: [id])
  267. user User @relation(fields: [userId], references: [id])
  268. @@index([userId, status])
  269. @@index([userId, endDate])
  270. @@index([planId], map: "Subscription_planId_fkey")
  271. }
  272. model TokenUsage {
  273. id Int @id @default(autoincrement())
  274. userId Int
  275. type String
  276. amount Int @default(0)
  277. contentLength Int @default(0)
  278. orderId Int?
  279. description String? @db.Text
  280. createdAt DateTime @default(now())
  281. order Order? @relation(fields: [orderId], references: [id])
  282. user User @relation(fields: [userId], references: [id])
  283. @@index([userId, createdAt])
  284. @@index([userId, type])
  285. @@index([orderId], map: "TokenUsage_orderId_fkey")
  286. }
  287. model TokenBalance {
  288. id Int @id @default(autoincrement())
  289. userId Int @unique
  290. totalTokens Int @default(0)
  291. usedTokens Int @default(0)
  292. resetDate DateTime?
  293. createdAt DateTime @default(now())
  294. updatedAt DateTime @updatedAt
  295. user User @relation(fields: [userId], references: [id])
  296. @@index([userId])
  297. }
  298. model VideoMaterial {
  299. id Int @id @default(autoincrement())
  300. userId Int?
  301. type String
  302. name String
  303. url String @db.Text
  304. thumbnail String?
  305. tags String? @db.Text
  306. category String?
  307. duration Int?
  308. size Int?
  309. width Int?
  310. height Int?
  311. createdAt DateTime @default(now())
  312. updatedAt DateTime @updatedAt
  313. @@index([userId, type])
  314. @@index([type, category])
  315. }
  316. model AudioRecord {
  317. id Int @id @default(autoincrement())
  318. userId Int?
  319. audioId String @unique
  320. title String @default("未命名音频")
  321. text String? @db.LongText
  322. wordCount Int @default(0)
  323. voiceId String @default("cherry")
  324. voiceParams String?
  325. audioUrl String? @db.Text
  326. audioDuration Int @default(0)
  327. audioSize Int @default(0)
  328. status String @default("processing")
  329. errorMsg String? @db.Text
  330. createdAt DateTime @default(now())
  331. updatedAt DateTime @updatedAt
  332. bookId Int?
  333. @@index([userId])
  334. @@index([audioId])
  335. @@index([bookId])
  336. }
  337. model PlatformAccount {
  338. id Int @id @default(autoincrement())
  339. userId Int
  340. platform String
  341. nickname String @default("")
  342. avatar String @default("")
  343. cookies String @db.Text
  344. headers String? @db.Text
  345. isValid Boolean @default(true)
  346. expireTime DateTime?
  347. createdAt DateTime @default(now())
  348. updatedAt DateTime @updatedAt
  349. @@unique([userId, platform])
  350. @@index([userId])
  351. @@index([platform])
  352. }
  353. model PublishTask {
  354. id Int @id @default(autoincrement())
  355. userId Int
  356. videoProjectId Int
  357. platform String
  358. title String @db.Text
  359. description String? @db.Text
  360. tags String? @db.Text
  361. coverUrl String? @db.Text
  362. videoUrl String? @db.Text
  363. status String @default("pending")
  364. errorMsg String? @db.Text
  365. publishedUrl String? @db.Text
  366. createdAt DateTime @default(now())
  367. updatedAt DateTime @updatedAt
  368. @@index([userId, platform])
  369. @@index([status])
  370. }
  371. model Draft {
  372. id Int @id @default(autoincrement())
  373. userId Int
  374. type String
  375. title String? @db.Text
  376. content String? @db.LongText
  377. metadata String? @db.Text
  378. autoSavedAt DateTime?
  379. createdAt DateTime @default(now())
  380. updatedAt DateTime @updatedAt
  381. user User @relation(fields: [userId], references: [id])
  382. @@index([userId, type])
  383. @@index([userId, updatedAt])
  384. }
  385. model Playlist {
  386. id Int @id @default(autoincrement())
  387. userId Int
  388. name String
  389. description String? @db.Text
  390. createdAt DateTime @default(now())
  391. updatedAt DateTime @updatedAt
  392. user User @relation(fields: [userId], references: [id])
  393. items PlaylistItem[]
  394. @@index([userId])
  395. }
  396. model PlaylistItem {
  397. id Int @id @default(autoincrement())
  398. playlistId Int
  399. chapterId Int?
  400. audioId String?
  401. order Int @default(0)
  402. chapter BookChapter? @relation(fields: [chapterId], references: [id])
  403. playlist Playlist @relation(fields: [playlistId], references: [id], onDelete: Cascade)
  404. @@index([playlistId, order])
  405. @@index([chapterId], map: "PlaylistItem_chapterId_fkey")
  406. }
  407. model Feedback {
  408. id String @id @default(uuid())
  409. type String
  410. title String @db.Text
  411. content String @db.Text
  412. contact String @db.Text
  413. screenshotUrls String @db.Text
  414. status String @default("submitted")
  415. createdAt DateTime @default(now())
  416. updatedAt DateTime @updatedAt
  417. @@index([type])
  418. @@index([status])
  419. @@index([createdAt])
  420. }