auth.prisma 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. model User {
  2. id String @id @default(cuid())
  3. name String
  4. email String @unique
  5. emailVerified Boolean @default(false)
  6. /// The mobile a technician signs in with, and the number a workshop holds
  7. /// for whoever this is.
  8. ///
  9. /// Deliberately not unique. When a desk creates an account for a mechanic
  10. /// standing at the counter, a second workshop may create another for the
  11. /// same human, and neither should be able to block the other. Every lookup
  12. /// reaches it through a technician row and so is already scoped to one
  13. /// workshop; the number alone is never the question being asked.
  14. phone String?
  15. image String?
  16. isSuperAdmin Boolean @default(false)
  17. createdAt DateTime @default(now())
  18. updatedAt DateTime @updatedAt
  19. twoFactorEnabled Boolean @default(false)
  20. termsAcceptedAt DateTime?
  21. lastLogin DateTime?
  22. lastSeen DateTime?
  23. /// App version this user last saw/dismissed the update banner for.
  24. /// Null = never seeded (seeded silently on first load, no banner).
  25. lastSeenVersion String?
  26. /// The release the update banner is up for, and when it first appeared to
  27. /// this user on any device. The hour it stays up runs from here, so a
  28. /// second device does not restart them and a closed tab cannot stop them.
  29. updateBannerVersion String?
  30. updateBannerShownAt DateTime?
  31. /// When this user last opened the "What's new" panel. Entries published
  32. /// after it (and after the account was created) carry the unread dot.
  33. whatsNewSeenAt DateTime?
  34. /// Per-user dashboard grid layout (card positions/sizes/hidden set).
  35. /// Null = default layout. Shape validated in dashboardLayoutActions.
  36. dashboardLayout Json?
  37. /// This person's keyboard shortcuts: only what differs from the defaults
  38. /// in features/shortcuts/Lib/registry.ts. Null = every default as shipped.
  39. /// Shape validated in features/shortcuts/Schema/preferences.ts.
  40. keyboardShortcuts Json?
  41. sessions Session[]
  42. portalMessages PortalMessage[]
  43. devices UserDevice[]
  44. accounts Account[]
  45. pushDevices PushDevice[]
  46. appSetupCodes TechnicianSetupCode[]
  47. vehicles Vehicle[]
  48. customers Customer[]
  49. settings AppSetting[]
  50. inventoryParts InventoryPart[]
  51. quotes Quote[]
  52. customFieldDefinitions CustomFieldDefinition[]
  53. twoFactor TwoFactor?
  54. passkeys Passkey[]
  55. organizationMembers OrganizationMember[]
  56. dashboardWidgets DashboardWidget[]
  57. auditLogs AuditLog[]
  58. openedServiceRecords ServiceRecord[] @relation("ServiceRecordCreatedBy")
  59. confirmedConcerns ServiceConcern[] @relation("ConcernConfirmedBy")
  60. appointmentsCreated Appointment[] @relation("AppointmentCreatedBy")
  61. appointmentNotifications AppointmentNotification[] @relation("AppointmentNotificationUser")
  62. recordedConditionMarks ConditionMark[] @relation("ConditionMarkRecordedBy")
  63. resolvedConditionMarks ConditionMark[] @relation("ConditionMarkResolvedBy")
  64. technicians Technician[]
  65. stockMovements StockMovement[]
  66. tireWarehouses TireWarehouse[]
  67. tireSets TireSet[]
  68. tireSetAttachments TireSetAttachment[]
  69. tireMeasurements TireMeasurement[]
  70. tireMovements TireMovement[]
  71. tireTreatments TireTreatment[]
  72. importBatches ImportBatch[]
  73. @@map("users")
  74. }
  75. model Session {
  76. id String @id @default(cuid())
  77. expiresAt DateTime
  78. token String @unique
  79. createdAt DateTime @default(now())
  80. updatedAt DateTime @updatedAt
  81. ipAddress String?
  82. userAgent String?
  83. userId String
  84. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  85. /// The one workshop this session may act in, for sessions minted without a
  86. /// password: an app setup code from the desk, or a one-time code sent to a
  87. /// technician's phone. Null for every ordinary sign-in.
  88. ///
  89. /// Those sessions are handed out on a workshop's say-so, and a workshop can
  90. /// only vouch for itself. Left unscoped, the token was the person's whole
  91. /// account: whoever redeemed a setup code could name any other workshop the
  92. /// technician belongs to in a header and act there with their role. When
  93. /// this is set it is the workshop, and no header or cookie can choose
  94. /// another. Removing the workshop ends the session with it.
  95. organizationId String?
  96. organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  97. @@index([userId])
  98. @@index([organizationId])
  99. @@map("sessions")
  100. }
  101. model Account {
  102. id String @id @default(cuid())
  103. accountId String
  104. providerId String
  105. userId String
  106. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  107. accessToken String?
  108. refreshToken String?
  109. idToken String?
  110. accessTokenExpiresAt DateTime?
  111. refreshTokenExpiresAt DateTime?
  112. scope String?
  113. password String?
  114. createdAt DateTime @default(now())
  115. updatedAt DateTime @updatedAt
  116. @@index([userId])
  117. @@map("accounts")
  118. }
  119. model Verification {
  120. id String @id @default(cuid())
  121. identifier String @unique
  122. value String
  123. expiresAt DateTime
  124. createdAt DateTime? @default(now())
  125. updatedAt DateTime? @updatedAt
  126. @@map("verifications")
  127. }
  128. model TwoFactor {
  129. id String @id @default(cuid())
  130. secret String
  131. backupCodes String
  132. userId String @unique
  133. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  134. // better-auth's two-factor plugin writes these three since 1.6: a secret
  135. // stays unverified until the first code is entered, and repeated wrong
  136. // codes lock the method for a while. Rows from before default to verified,
  137. // because those people already proved their app worked.
  138. verified Boolean @default(true)
  139. failedVerificationCount Int @default(0)
  140. lockedUntil DateTime?
  141. @@map("two_factor")
  142. }
  143. model Passkey {
  144. id String @id @default(cuid())
  145. name String?
  146. publicKey String
  147. userId String
  148. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  149. credentialID String @unique
  150. counter Int
  151. deviceType String
  152. backedUp Boolean
  153. transports String?
  154. aaguid String?
  155. createdAt DateTime @default(now())
  156. @@index([userId])
  157. @@map("passkeys")
  158. }
  159. /// A browser or phone this person has signed in from before.
  160. ///
  161. /// Sessions come and go (sign-out, expiry, a password change that ends the
  162. /// others), so the session table cannot say whether a device is new; this can.
  163. /// A browser is known by a random id in a long-lived cookie, set the first
  164. /// time it signs in; a client without cookies, such as the technician app,
  165. /// is known by its user agent. The first device an account ever sees is
  166. /// recorded quietly; every later one earns a "new sign-in" mail.
  167. model UserDevice {
  168. id String @id @default(cuid())
  169. /// Cookie id, or a hash of the user agent when no cookie can be kept.
  170. deviceKey String
  171. userAgent String?
  172. lastIp String?
  173. firstSeenAt DateTime @default(now())
  174. lastSeenAt DateTime @default(now())
  175. userId String
  176. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  177. @@unique([userId, deviceKey])
  178. @@index([userId])
  179. @@map("user_devices")
  180. }