organization.prisma 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. model AppSetting {
  2. id String @id @default(cuid())
  3. key String
  4. value String
  5. userId String
  6. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  7. organizationId String?
  8. organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  9. @@unique([organizationId, key])
  10. @@index([organizationId])
  11. @@map("app_settings")
  12. }
  13. /// A user-defined dashboard card: a named, filtered table over one entity.
  14. /// The config shape (entity, filters, columns, limit) is validated against
  15. /// the field registry in customCardActions — nothing here reaches SQL raw.
  16. model DashboardWidget {
  17. id String @id @default(cuid())
  18. name String
  19. config Json
  20. userId String
  21. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  22. organizationId String
  23. createdAt DateTime @default(now())
  24. updatedAt DateTime @updatedAt
  25. @@index([userId, organizationId])
  26. @@map("dashboard_widgets")
  27. }
  28. model Organization {
  29. id String @id @default(cuid())
  30. name String
  31. portalSlug String? @unique
  32. /// The secret in this workshop's reply address (`reply-<token>@…`) on the
  33. /// cloud instance. Minted by the first customer mail that needs one; never
  34. /// the organization id, which anyone could guess.
  35. replyMailToken String? @unique
  36. createdAt DateTime @default(now())
  37. updatedAt DateTime @updatedAt
  38. members OrganizationMember[]
  39. roles Role[]
  40. vehicles Vehicle[]
  41. serviceRecords ServiceRecord[]
  42. reminders Reminder[]
  43. appointments Appointment[]
  44. appointmentNotifications AppointmentNotification[]
  45. customers Customer[]
  46. quotes Quote[]
  47. inventoryParts InventoryPart[]
  48. laborPresets LaborPreset[]
  49. customFieldDefinitions CustomFieldDefinition[]
  50. settings AppSetting[]
  51. emailTemplates EmailTemplate[]
  52. subscription Subscription?
  53. invitations TeamInvitation[]
  54. inspectionTemplates InspectionTemplate[]
  55. conditionMarks ConditionMark[]
  56. conditionMarkTypes ConditionMarkType[]
  57. meterTypes MeterType[]
  58. vehicleMeters VehicleMeter[]
  59. meterReadings MeterReading[]
  60. equipmentTypes EquipmentType[]
  61. equipmentItems EquipmentItem[]
  62. equipmentFittings EquipmentFitting[]
  63. serviceRecordEquipment ServiceRecordEquipment[]
  64. quoteEquipment QuoteEquipment[]
  65. smsMessages SmsMessage[]
  66. telegramMessages TelegramMessage[]
  67. whatsappMessages WhatsappMessage[]
  68. portalMessages PortalMessage[]
  69. emailMessages EmailMessage[]
  70. technicians Technician[]
  71. workBays WorkBay[]
  72. timeEntries TimeEntry[]
  73. pushDevices PushDevice[]
  74. appSetupCodes TechnicianSetupCode[]
  75. scopedSessions Session[]
  76. technicianLoginCodes TechnicianLoginCode[]
  77. auditLogs AuditLog[]
  78. statusReports StatusReport[]
  79. reportSchedules ReportSchedule[]
  80. scheduledMessages ScheduledMessage[]
  81. webhooks Webhook[]
  82. stockMovements StockMovement[]
  83. tireWarehouses TireWarehouse[]
  84. tireLocations TireLocation[]
  85. tireSets TireSet[]
  86. workOrderStatuses WorkOrderStatus[]
  87. tireSetAttachments TireSetAttachment[]
  88. tireMovements TireMovement[]
  89. tireTreatments TireTreatment[]
  90. integrationConnections IntegrationConnection[]
  91. externalCalendarEvents ExternalCalendarEvent[]
  92. importBatches ImportBatch[]
  93. vehicleInspectionStatuses VehicleInspectionStatus[]
  94. inspectionReminderCampaigns InspectionReminderCampaign[]
  95. inspectionReminderSends InspectionReminderSend[]
  96. documentDesigns DocumentDesign[]
  97. documentDesignSnapshots DocumentDesignSnapshot[]
  98. documentAssetSnapshots DocumentAssetSnapshot[]
  99. backupRuns BackupRun[]
  100. workshopClosures WorkshopClosure[]
  101. technicianAbsences TechnicianAbsence[]
  102. serviceRecordHelpers ServiceRecordHelper[]
  103. platformBackup PlatformBackup?
  104. @@map("organizations")
  105. }
  106. model OrganizationMember {
  107. id String @id @default(cuid())
  108. role String @default("member")
  109. userId String
  110. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  111. organizationId String
  112. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  113. roleId String?
  114. customRole Role? @relation(fields: [roleId], references: [id], onDelete: SetNull)
  115. signature MemberSignature?
  116. @@unique([userId, organizationId])
  117. @@map("organization_members")
  118. }
  119. /// A member's handwritten signature, drawn or uploaded in account settings,
  120. /// for the Signature section of the documents they issue.
  121. ///
  122. /// Kept per workshop rather than per person: a mechanic who works for two
  123. /// shops signs each one's paper, and leaving a workshop takes the signature
  124. /// with the membership. The image is held in the row (a PNG or JPEG of a few
  125. /// kilobytes) so a document can print it without the upload folder, and so
  126. /// replacing it never touches a file an issued invoice still needs; issued
  127. /// documents keep their own copy in DocumentAssetSnapshot.
  128. model MemberSignature {
  129. id String @id @default(cuid())
  130. memberId String @unique
  131. member OrganizationMember @relation(fields: [memberId], references: [id], onDelete: Cascade)
  132. mimeType String
  133. data Bytes
  134. createdAt DateTime @default(now())
  135. updatedAt DateTime @updatedAt
  136. @@map("member_signatures")
  137. }
  138. model Role {
  139. id String @id @default(cuid())
  140. name String
  141. isAdmin Boolean @default(false)
  142. createdAt DateTime @default(now())
  143. updatedAt DateTime @updatedAt
  144. organizationId String
  145. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  146. permissions Permission[]
  147. members OrganizationMember[]
  148. teamInvitations TeamInvitation[]
  149. @@unique([organizationId, name])
  150. @@map("roles")
  151. }
  152. model Permission {
  153. id String @id @default(cuid())
  154. action String
  155. subject String
  156. roleId String
  157. role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
  158. @@unique([roleId, action, subject])
  159. @@index([roleId])
  160. @@map("permissions")
  161. }
  162. model SystemSetting {
  163. id String @id @default(cuid())
  164. key String @unique
  165. value String
  166. @@map("system_settings")
  167. }
  168. model TeamInvitation {
  169. id String @id @default(cuid())
  170. email String
  171. role String @default("member")
  172. token String @unique
  173. status String @default("pending") // pending | accepted | cancelled
  174. expiresAt DateTime
  175. createdAt DateTime @default(now())
  176. organizationId String
  177. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  178. invitedById String
  179. roleId String?
  180. customRole Role? @relation(fields: [roleId], references: [id], onDelete: SetNull)
  181. @@unique([email, organizationId])
  182. @@index([token])
  183. @@map("team_invitations")
  184. }
  185. /// Customer mail a workshop sent through the platform's own address in one
  186. /// day, for the daily cap on plans without custom email
  187. /// (src/features/email/Lib/emailAllowance.ts). In the database rather than in
  188. /// memory, so a restart or a second server does not hand out a fresh allowance.
  189. /// A slot is taken just before a mail goes out and given back if it fails.
  190. model PlatformMailUsage {
  191. organizationId String
  192. /// The UTC day, YYYY-MM-DD
  193. day String
  194. count Int @default(0)
  195. @@id([organizationId, day])
  196. @@map("platform_mail_usage")
  197. }
  198. /// How many texts a workshop has sent through the platform's SMS account on
  199. /// one day. Same shape and the same reason as the mail table above: the count
  200. /// has to survive a restart, and a slot is given back when a send fails.
  201. model PlatformSmsUsage {
  202. organizationId String
  203. /// The UTC day, YYYY-MM-DD
  204. day String
  205. count Int @default(0)
  206. @@id([organizationId, day])
  207. @@map("platform_sms_usage")
  208. }