auth.prisma 7.0 KB

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