auth.prisma 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. /// Per-user dashboard grid layout (card positions/sizes/hidden set).
  32. /// Null = default layout. Shape validated in dashboardLayoutActions.
  33. dashboardLayout Json?
  34. sessions Session[]
  35. devices UserDevice[]
  36. accounts Account[]
  37. pushDevices PushDevice[]
  38. appSetupCodes TechnicianSetupCode[]
  39. vehicles Vehicle[]
  40. customers Customer[]
  41. settings AppSetting[]
  42. inventoryParts InventoryPart[]
  43. quotes Quote[]
  44. customFieldDefinitions CustomFieldDefinition[]
  45. twoFactor TwoFactor?
  46. passkeys Passkey[]
  47. organizationMembers OrganizationMember[]
  48. dashboardWidgets DashboardWidget[]
  49. auditLogs AuditLog[]
  50. openedServiceRecords ServiceRecord[] @relation("ServiceRecordCreatedBy")
  51. confirmedConcerns ServiceConcern[] @relation("ConcernConfirmedBy")
  52. appointmentsCreated Appointment[] @relation("AppointmentCreatedBy")
  53. appointmentNotifications AppointmentNotification[] @relation("AppointmentNotificationUser")
  54. recordedConditionMarks ConditionMark[] @relation("ConditionMarkRecordedBy")
  55. resolvedConditionMarks ConditionMark[] @relation("ConditionMarkResolvedBy")
  56. technicians Technician[]
  57. stockMovements StockMovement[]
  58. tireWarehouses TireWarehouse[]
  59. tireSets TireSet[]
  60. tireSetAttachments TireSetAttachment[]
  61. tireMeasurements TireMeasurement[]
  62. tireMovements TireMovement[]
  63. tireTreatments TireTreatment[]
  64. importBatches ImportBatch[]
  65. @@map("users")
  66. }
  67. model Session {
  68. id String @id @default(cuid())
  69. expiresAt DateTime
  70. token String @unique
  71. createdAt DateTime @default(now())
  72. updatedAt DateTime @updatedAt
  73. ipAddress String?
  74. userAgent String?
  75. userId String
  76. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  77. /// The one workshop this session may act in, for sessions minted without a
  78. /// password: an app setup code from the desk, or a one-time code sent to a
  79. /// technician's phone. Null for every ordinary sign-in.
  80. ///
  81. /// Those sessions are handed out on a workshop's say-so, and a workshop can
  82. /// only vouch for itself. Left unscoped, the token was the person's whole
  83. /// account: whoever redeemed a setup code could name any other workshop the
  84. /// technician belongs to in a header and act there with their role. When
  85. /// this is set it is the workshop, and no header or cookie can choose
  86. /// another. Removing the workshop ends the session with it.
  87. organizationId String?
  88. organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  89. @@index([userId])
  90. @@index([organizationId])
  91. @@map("sessions")
  92. }
  93. model Account {
  94. id String @id @default(cuid())
  95. accountId String
  96. providerId String
  97. userId String
  98. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  99. accessToken String?
  100. refreshToken String?
  101. idToken String?
  102. accessTokenExpiresAt DateTime?
  103. refreshTokenExpiresAt DateTime?
  104. scope String?
  105. password String?
  106. createdAt DateTime @default(now())
  107. updatedAt DateTime @updatedAt
  108. @@index([userId])
  109. @@map("accounts")
  110. }
  111. model Verification {
  112. id String @id @default(cuid())
  113. identifier String @unique
  114. value String
  115. expiresAt DateTime
  116. createdAt DateTime? @default(now())
  117. updatedAt DateTime? @updatedAt
  118. @@map("verifications")
  119. }
  120. model TwoFactor {
  121. id String @id @default(cuid())
  122. secret String
  123. backupCodes String
  124. userId String @unique
  125. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  126. // better-auth's two-factor plugin writes these three since 1.6: a secret
  127. // stays unverified until the first code is entered, and repeated wrong
  128. // codes lock the method for a while. Rows from before default to verified,
  129. // because those people already proved their app worked.
  130. verified Boolean @default(true)
  131. failedVerificationCount Int @default(0)
  132. lockedUntil DateTime?
  133. @@map("two_factor")
  134. }
  135. model Passkey {
  136. id String @id @default(cuid())
  137. name String?
  138. publicKey String
  139. userId String
  140. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  141. credentialID String @unique
  142. counter Int
  143. deviceType String
  144. backedUp Boolean
  145. transports String?
  146. aaguid String?
  147. createdAt DateTime @default(now())
  148. @@index([userId])
  149. @@map("passkeys")
  150. }
  151. /// A browser or phone this person has signed in from before.
  152. ///
  153. /// Sessions come and go (sign-out, expiry, a password change that ends the
  154. /// others), so the session table cannot say whether a device is new; this can.
  155. /// A browser is known by a random id in a long-lived cookie, set the first
  156. /// time it signs in; a client without cookies, such as the technician app,
  157. /// is known by its user agent. The first device an account ever sees is
  158. /// recorded quietly; every later one earns a "new sign-in" mail.
  159. model UserDevice {
  160. id String @id @default(cuid())
  161. /// Cookie id, or a hash of the user agent when no cookie can be kept.
  162. deviceKey String
  163. userAgent String?
  164. lastIp String?
  165. firstSeenAt DateTime @default(now())
  166. lastSeenAt DateTime @default(now())
  167. userId String
  168. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  169. @@unique([userId, deviceKey])
  170. @@index([userId])
  171. @@map("user_devices")
  172. }