4
0

auth.prisma 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. @@index([userId])
  76. @@map("sessions")
  77. }
  78. model Account {
  79. id String @id @default(cuid())
  80. accountId String
  81. providerId String
  82. userId String
  83. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  84. accessToken String?
  85. refreshToken String?
  86. idToken String?
  87. accessTokenExpiresAt DateTime?
  88. refreshTokenExpiresAt DateTime?
  89. scope String?
  90. password String?
  91. createdAt DateTime @default(now())
  92. updatedAt DateTime @updatedAt
  93. @@index([userId])
  94. @@map("accounts")
  95. }
  96. model Verification {
  97. id String @id @default(cuid())
  98. identifier String @unique
  99. value String
  100. expiresAt DateTime
  101. createdAt DateTime? @default(now())
  102. updatedAt DateTime? @updatedAt
  103. @@map("verifications")
  104. }
  105. model TwoFactor {
  106. id String @id @default(cuid())
  107. secret String
  108. backupCodes String
  109. userId String @unique
  110. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  111. // better-auth's two-factor plugin writes these three since 1.6: a secret
  112. // stays unverified until the first code is entered, and repeated wrong
  113. // codes lock the method for a while. Rows from before default to verified,
  114. // because those people already proved their app worked.
  115. verified Boolean @default(true)
  116. failedVerificationCount Int @default(0)
  117. lockedUntil DateTime?
  118. @@map("two_factor")
  119. }
  120. model Passkey {
  121. id String @id @default(cuid())
  122. name String?
  123. publicKey String
  124. userId String
  125. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  126. credentialID String @unique
  127. counter Int
  128. deviceType String
  129. backedUp Boolean
  130. transports String?
  131. aaguid String?
  132. createdAt DateTime @default(now())
  133. @@index([userId])
  134. @@map("passkeys")
  135. }
  136. /// A browser or phone this person has signed in from before.
  137. ///
  138. /// Sessions come and go (sign-out, expiry, a password change that ends the
  139. /// others), so the session table cannot say whether a device is new; this can.
  140. /// A browser is known by a random id in a long-lived cookie, set the first
  141. /// time it signs in; a client without cookies, such as the technician app,
  142. /// is known by its user agent. The first device an account ever sees is
  143. /// recorded quietly; every later one earns a "new sign-in" mail.
  144. model UserDevice {
  145. id String @id @default(cuid())
  146. /// Cookie id, or a hash of the user agent when no cookie can be kept.
  147. deviceKey String
  148. userAgent String?
  149. lastIp String?
  150. firstSeenAt DateTime @default(now())
  151. lastSeenAt DateTime @default(now())
  152. userId String
  153. user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  154. @@unique([userId, deviceKey])
  155. @@index([userId])
  156. @@map("user_devices")
  157. }