schema.prisma 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. generator client {
  2. provider = "prisma-client-js"
  3. binaryTargets = ["native", "windows"]
  4. }
  5. datasource mysql {
  6. provider = "mysql"
  7. url = env("DATABASE_URL")
  8. }
  9. model Station {
  10. id Int @id @default(autoincrement())
  11. name String
  12. long Decimal?
  13. lat Decimal?
  14. address String?
  15. city String?
  16. country String?
  17. municipality String?
  18. description String?
  19. stationCompanies StationCompany[]
  20. trajetsDepartingFrom Trajet[] @relation("TrajetsDepartingFrom") // Ajout de la relation inverse
  21. trajetsArrivingAt Trajet[] @relation("TrajetsArrivingAt") // Ajout de la relation inverse
  22. }
  23. model Company {
  24. id Int @id @default(autoincrement())
  25. name String @unique
  26. address String
  27. managerId Int @unique
  28. manager User @relation("CompanyManager", fields: [managerId], references: [id])
  29. employees User[] @relation("CompanyEmployees")
  30. drivers Driver[] @relation("CompanyDrivers")
  31. stationCompanies StationCompany[]
  32. vehicules Vehicule[] @relation("CompanyVehicules")
  33. trajets Trajet[] @relation("CompanyTrajets") // Relation inverse avec Trajet
  34. }
  35. model StationCompany {
  36. id Int @id @default(autoincrement())
  37. stationId Int
  38. companyId Int
  39. stationChiefId Int
  40. company Company @relation(fields: [companyId], references: [id])
  41. stationChief User @relation("UserStationChief", fields: [stationChiefId], references: [id])
  42. station Station @relation(fields: [stationId], references: [id])
  43. @@unique([stationId, companyId])
  44. @@index([companyId], map: "StationCompany_companyId_fkey")
  45. @@index([stationChiefId], map: "StationCompany_stationChiefId_fkey")
  46. }
  47. model Driver {
  48. id Int @id @default(autoincrement())
  49. name String @unique
  50. address String
  51. telephone String
  52. companyId Int?
  53. userId Int @unique
  54. company Company? @relation("CompanyDrivers", fields: [companyId], references: [id])
  55. user User @relation("UserDriver", fields: [userId], references: [id])
  56. vehicules Vehicule[] @relation("DriverVehicules")
  57. @@index([companyId], map: "Driver_companyId_fkey")
  58. }
  59. model User {
  60. id Int @id @default(autoincrement())
  61. name String?
  62. otherName String?
  63. address String?
  64. telephone String?
  65. email String @unique
  66. password String
  67. role UserRole @default(USER)
  68. companyId Int? // Nouveau champ pour la relation employé-entreprise
  69. company Company? @relation("CompanyEmployees", fields: [companyId], references: [id])
  70. managedCompany Company? @relation("CompanyManager")
  71. driver Driver? @relation("UserDriver")
  72. reservations Reservation[] @relation("UserReservations")
  73. stationCompanies StationCompany[] @relation("UserStationChief")
  74. transactions Transaction[] @relation("UserTransactions")
  75. managedTrajets Trajet[] @relation("TrajetEmployee") // Trajets dont l'utilisateur est responsable
  76. @@index([companyId], map: "User_companyId_fkey")
  77. }
  78. model Vehicule {
  79. id Int @id @default(autoincrement())
  80. number_places Int
  81. color String
  82. type String
  83. immatriculation String @unique
  84. model String
  85. companyId Int
  86. driverId Int?
  87. status VehiculeStatus @default(INACTIF)
  88. places Place[] @relation("VehiculePlaces")
  89. trajets Trajet[] @relation("VehiculeTrajets")
  90. company Company @relation("CompanyVehicules", fields: [companyId], references: [id])
  91. driver Driver? @relation("DriverVehicules", fields: [driverId], references: [id])
  92. @@index([companyId], map: "Vehicule_companyId_fkey")
  93. @@index([driverId], map: "Vehicule_driverId_fkey")
  94. }
  95. model Place {
  96. id Int @id @default(autoincrement())
  97. number Int
  98. vehiculeId Int
  99. isAvailable Boolean @default(true) // Indique si la place est disponible
  100. occupiedAt DateTime? // Date d'occupation si la place est occupée
  101. vehicule Vehicule @relation("VehiculePlaces", fields: [vehiculeId], references: [id])
  102. reservations Reservation[] @relation("PlaceReservations")
  103. @@index([vehiculeId], map: "Place_vehiculeId_fkey")
  104. }
  105. model Trajet {
  106. id Int @id @default(autoincrement())
  107. departAt DateTime
  108. arriveAt DateTime
  109. // depart String // Ancien champ
  110. // arrive String // Ancien champ
  111. departStationId Int // Nouveau champ pour l'ID de la station de départ
  112. arriveStationId Int // Nouveau champ pour l'ID de la station d'arrivée
  113. vehiculeId Int
  114. companyId Int? // Relation directe avec Company (optionnel temporairement)
  115. employeeId Int? // ID de l'employé responsable du trajet
  116. pricePerSeat Float @default(0.0) // Prix par place
  117. reservations Reservation[] @relation("TrajetReservations")
  118. vehicule Vehicule @relation("VehiculeTrajets", fields: [vehiculeId], references: [id])
  119. company Company? @relation("CompanyTrajets", fields: [companyId], references: [id]) // Relation directe avec Company
  120. employee User? @relation("TrajetEmployee", fields: [employeeId], references: [id]) // Relation vers l'employé responsable
  121. departStation Station @relation("TrajetsDepartingFrom", fields: [departStationId], references: [id]) // Relation vers la station de départ
  122. arriveStation Station @relation("TrajetsArrivingAt", fields: [arriveStationId], references: [id]) // Relation vers la station d'arrivée
  123. @@index([vehiculeId], map: "Trajet_vehiculeId_fkey")
  124. @@index([companyId], map: "Trajet_companyId_fkey") // Index pour la relation avec Company
  125. @@index([employeeId], map: "Trajet_employeeId_fkey") // Index pour la relation avec l'employé
  126. @@index([departStationId], map: "Trajet_departStationId_fkey") // Index pour la nouvelle clé étrangère
  127. @@index([arriveStationId], map: "Trajet_arriveStationId_fkey") // Index pour la nouvelle clé étrangère
  128. }
  129. model Reservation {
  130. id Int @id @default(autoincrement())
  131. dateAt DateTime
  132. placeId Int
  133. userId Int
  134. trajetId Int
  135. qrcode Qrcode? @relation("ReservationQrcode")
  136. place Place @relation("PlaceReservations", fields: [placeId], references: [id])
  137. trajet Trajet @relation("TrajetReservations", fields: [trajetId], references: [id])
  138. user User @relation("UserReservations", fields: [userId], references: [id])
  139. transaction Transaction? @relation("ReservationTransaction")
  140. @@index([placeId], map: "Reservation_placeId_fkey")
  141. @@index([trajetId], map: "Reservation_trajetId_fkey")
  142. @@index([userId], map: "Reservation_userId_fkey")
  143. }
  144. model Transaction {
  145. id String @id @default(uuid())
  146. amount Float?
  147. currency String?
  148. status String?
  149. provider String?
  150. reference String?
  151. metadata Json?
  152. createdAt DateTime? @default(now())
  153. updatedAt DateTime? @updatedAt
  154. userId Int @unique
  155. reservationId Int @unique
  156. // Champs PayDunya
  157. paydunya_token String? @unique
  158. paydunya_transaction_id String? @unique
  159. paydunya_invoice_url String?
  160. payment_method String? // "mobile_money", "card", "bank_transfer"
  161. payment_type String? // "invoice", "dmp", "softpay"
  162. paydunya_response Json? // Réponse complète de PayDunya
  163. webhook_data Json? // Données reçues via webhook
  164. // Champs CinetPay
  165. cinetpay_transaction_id String?
  166. cinetpay_payment_token String?
  167. cinetpay_payment_url String?
  168. cinetpay_response Json? // Réponse complète de CinetPay
  169. cinetpay_webhook_data Json? // Données webhook CinetPay
  170. cinetpay_payment_method String? // "mobile_money", "credit_card", "wallet"
  171. cinetpay_operator_id String? // ID de l'opérateur (Orange, MTN, etc.)
  172. cinetpay_phone_number String? // Numéro de téléphone utilisé
  173. cinetpay_payment_date DateTime? // Date de paiement confirmée
  174. reservation Reservation @relation("ReservationTransaction", fields: [reservationId], references: [id])
  175. user User @relation("UserTransactions", fields: [userId], references: [id])
  176. @@index([userId], map: "Transaction_userId_fkey")
  177. @@index([paydunya_token], map: "Transaction_paydunya_token_idx")
  178. @@index([paydunya_transaction_id], map: "Transaction_paydunya_transaction_id_idx")
  179. @@index([payment_method], map: "Transaction_payment_method_idx")
  180. @@index([payment_type], map: "Transaction_payment_type_idx")
  181. @@index([cinetpay_payment_method], map: "Transaction_cinetpay_payment_method_idx")
  182. @@index([provider], map: "Transaction_provider_idx")
  183. @@index([status], map: "Transaction_status_idx")
  184. }
  185. model Qrcode {
  186. id String @id @default(uuid())
  187. reservationId Int @unique
  188. createdAt DateTime @default(now())
  189. scannedAt DateTime?
  190. value String
  191. reservation Reservation @relation("ReservationQrcode", fields: [reservationId], references: [id])
  192. }
  193. enum UserRole {
  194. USER
  195. ADMIN
  196. DRIVER
  197. MANAGER
  198. EMPLOYEE
  199. }
  200. enum VehiculeStatus {
  201. ACTIF
  202. INACTIF
  203. MAINTENANCE
  204. }