schema.prisma 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // This is your Prisma schema file,
  2. // learn more about it in the docs: https://pris.ly/d/prisma-schema
  3. generator client {
  4. provider = "prisma-client-js"
  5. output = "../generated/prisma"
  6. }
  7. datasource db {
  8. provider = "postgresql"
  9. // NOTE: When using mysql or sqlserver, uncomment the @db.Text annotations in model Account below
  10. // Further reading:
  11. // https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
  12. // https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
  13. url = env("DATABASE_URL")
  14. }
  15. // Workspace — 1 utilisateur = 1 workspace (MVP). Unité de tenant pour AImpact Hub (Story 1.2)
  16. // Story 1.6: tier, llmCallsThisMonth, llmCallsResetAt pour limites Free (FR4, FR5)
  17. enum WorkspaceTier {
  18. FREE
  19. PRO
  20. }
  21. model Workspace {
  22. id String @id @default(cuid())
  23. name String
  24. slug String @unique
  25. sector String?
  26. companySize Int?
  27. contactEmail String?
  28. tier WorkspaceTier @default(FREE)
  29. llmCallsThisMonth Int @default(0)
  30. llmCallsResetAt DateTime @default(now())
  31. autoRelanceEnabled Boolean @default(true) // Story 2.10 : désactivable par le Transformateur
  32. createdAt DateTime @default(now())
  33. updatedAt DateTime @updatedAt
  34. ownerId String @unique
  35. owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
  36. contributors Contributor[]
  37. ideas Idea[]
  38. manualRelanceLogs ManualRelanceLog[]
  39. }
  40. // Story 2.11 : Relance manuelle Transformateur (FR11, FR12, FR13)
  41. model ManualRelanceLog {
  42. id String @id @default(cuid())
  43. workspaceId String
  44. subject String
  45. recipientCount Int
  46. sentCount Int
  47. failedCount Int @default(0)
  48. sentAt DateTime @default(now())
  49. workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
  50. @@index([workspaceId])
  51. }
  52. // Story 2.1: Invitation contributeurs (FR6, FR7)
  53. enum ContributorStatus {
  54. INVITED
  55. SUBMITTED
  56. NOT_SUBMITTED
  57. }
  58. model Contributor {
  59. id String @id @default(cuid())
  60. workspaceId String
  61. workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
  62. email String
  63. status ContributorStatus @default(INVITED)
  64. invitedAt DateTime @default(now())
  65. lastRemindedAt DateTime? // Story 2.10 : date de la relance J+21 (null = jamais relancé)
  66. createdAt DateTime @default(now())
  67. ideas Idea[]
  68. @@unique([workspaceId, email])
  69. @@index([workspaceId])
  70. }
  71. // Story 2.2: Formulaire de soumission contributeur (FR8, FR14)
  72. enum IdeaStatus {
  73. SUBMITTED // Envoyé (statut initial)
  74. IN_REVIEW // En traitement
  75. ON_AGENDA // Mis à l'ordre du jour
  76. IN_PROGRESS // En cours
  77. NOT_PRIORITY // Non prioritaire (filtrable, non supprimé — FR26)
  78. }
  79. enum ImpactLevel {
  80. FAIBLE
  81. MODERE
  82. ELEVE
  83. CRITIQUE
  84. }
  85. enum Frequency {
  86. QUOTIDIENNE
  87. HEBDOMADAIRE
  88. MENSUELLE
  89. TRIMESTRIELLE
  90. PONCTUELLE
  91. }
  92. model Idea {
  93. id String @id @default(cuid())
  94. workspaceId String
  95. workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
  96. // Données contributeur
  97. contributorEmail String
  98. contributorId String?
  99. contributor Contributor? @relation(fields: [contributorId], references: [id], onDelete: SetNull)
  100. // Champs formulaire FR14
  101. department String
  102. problemDescription String @db.Text
  103. estimatedImpact ImpactLevel
  104. frequency Frequency
  105. // Statut
  106. status IdeaStatus @default(SUBMITTED)
  107. // Enrichissement LLM — rempli par Story 3.1 (api/llm/enrich)
  108. llmTitle String?
  109. llmDomain String?
  110. llmAiType String?
  111. llmExplanation String? @db.Text
  112. llmScoreImpact Int? // 1–5 (NFR18)
  113. llmScoreFeasibility Int? // 1–5
  114. llmScoreUrgency Int? // 1–5
  115. llmEnrichedAt DateTime?
  116. llmEnrichFailed Boolean @default(false) // FR21 : fallback "À qualifier manuellement"
  117. // Scores manuels — Story 3.4 (FR20)
  118. manualScoreImpact Int?
  119. manualScoreFeasibility Int?
  120. manualScoreUrgency Int?
  121. // Ordre priorisation — Story 4.3 (FR33)
  122. priorityOrder Int?
  123. // Story 2.5 : idempotence webhook Resend Inbound (éviter doublons sur replay)
  124. emailMessageId String? @unique
  125. // Story 2.6 : pièces jointes (FR17)
  126. attachments IdeaAttachment[]
  127. createdAt DateTime @default(now())
  128. updatedAt DateTime @updatedAt
  129. @@index([workspaceId, createdAt])
  130. @@index([workspaceId, status])
  131. @@index([workspaceId, contributorEmail])
  132. }
  133. model Post {
  134. id Int @id @default(autoincrement())
  135. name String
  136. createdAt DateTime @default(now())
  137. updatedAt DateTime @updatedAt
  138. createdBy User @relation(fields: [createdById], references: [id])
  139. createdById String
  140. @@index([name])
  141. }
  142. // Necessary for Next auth
  143. model Account {
  144. id String @id @default(cuid())
  145. userId String
  146. type String
  147. provider String
  148. providerAccountId String
  149. refresh_token String? // @db.Text
  150. access_token String? // @db.Text
  151. expires_at Int?
  152. token_type String?
  153. scope String?
  154. id_token String? // @db.Text
  155. session_state String?
  156. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  157. refresh_token_expires_in Int?
  158. @@unique([provider, providerAccountId])
  159. }
  160. model Session {
  161. id String @id @default(cuid())
  162. sessionToken String @unique
  163. userId String
  164. expires DateTime
  165. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  166. }
  167. model User {
  168. id String @id @default(cuid())
  169. name String?
  170. email String? @unique
  171. emailVerified DateTime?
  172. password String? // hash bcrypt — auth Credentials (Story 1.2b)
  173. image String?
  174. accounts Account[]
  175. sessions Session[]
  176. posts Post[]
  177. workspace Workspace?
  178. }
  179. model VerificationToken {
  180. identifier String
  181. token String @unique
  182. expires DateTime
  183. @@unique([identifier, token])
  184. }
  185. // Story 2.6 : Pièces jointes à la soumission (FR17)
  186. model IdeaAttachment {
  187. id String @id @default(cuid())
  188. ideaId String
  189. idea Idea @relation(fields: [ideaId], references: [id], onDelete: Cascade)
  190. workspaceId String // dénormalisé pour isolation multi-tenant
  191. filename String // nom original sanitisé
  192. contentType String // MIME type
  193. size Int // taille en bytes
  194. url String // URL Vercel Blob
  195. blobPath String // path convention : {workspaceId}/attachments/{ideaId}/{filename}
  196. createdAt DateTime @default(now())
  197. @@index([ideaId])
  198. @@index([workspaceId])
  199. }
  200. // Story 2.4a: Bibliothèque de cas d'usage IA (FR14-IA3, FR14-IA4, FR14-IA5)
  201. // Bibliothèque globale partagée — pas de workspaceId
  202. model LibraryCase {
  203. id String @id @default(cuid())
  204. sector String // distribution | industrie | services | sante | finance
  205. department String // rh | finance | supply-chain | commercial | operations
  206. title String
  207. description String @db.Text
  208. createdAt DateTime @default(now())
  209. updatedAt DateTime @updatedAt
  210. @@index([sector])
  211. @@index([department])
  212. @@index([sector, department])
  213. }