Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
schemas = ["public", "auth"]
}

generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
previewFeatures = ["multiSchema"]
}

enum Role {
Expand All @@ -14,6 +16,8 @@ enum Role {
DRIVER
SAFETY_OFFICER
FINANCIAL_ANALYST

@@schema("public")
}

enum VehicleStatus {
Expand All @@ -23,6 +27,8 @@ enum VehicleStatus {
retired

@@map("vehicle_status")

@@schema("public")
}

enum DriverStatus {
Expand All @@ -32,6 +38,8 @@ enum DriverStatus {
suspended

@@map("driver_status")

@@schema("public")
}

enum TripStatus {
Expand All @@ -41,20 +49,26 @@ enum TripStatus {
cancelled

@@map("trip_status")

@@schema("public")
}

enum MaintenanceType {
preventive
reactive

@@map("maintenance_type")

@@schema("public")
}

enum MaintenanceStatus {
open
closed

@@map("maintenance_status")

@@schema("public")
}

enum ExpenseCategory {
Expand All @@ -63,6 +77,8 @@ enum ExpenseCategory {
other

@@map("expense_category")

@@schema("public")
}

model User {
Expand All @@ -78,6 +94,8 @@ model User {
updatedAt DateTime @updatedAt @map("updatedAt")

@@map("users")

@@schema("public")
}

model Vehicle {
Expand All @@ -100,6 +118,8 @@ model Vehicle {
expenses Expense[]

@@map("vehicles")

@@schema("public")
}

model Driver {
Expand All @@ -115,8 +135,11 @@ model Driver {
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
trips Trip[]
safetyScoreHistory SafetyScoreHistory[]

@@map("drivers")

@@schema("public")
}

model Trip {
Expand All @@ -143,6 +166,8 @@ model Trip {
expenses Expense[]

@@map("trips")

@@schema("public")
}

model MaintenanceRecord {
Expand All @@ -158,6 +183,8 @@ model MaintenanceRecord {
vehicle Vehicle @relation(fields: [vehicleId], references: [id])

@@map("maintenance_records")

@@schema("public")
}

model Expense {
Expand All @@ -175,4 +202,23 @@ model Expense {
trip Trip? @relation(fields: [tripId], references: [id])

@@map("expenses")

@@schema("public")
}

model SafetyScoreHistory {
id String @id @default(uuid())
driverId String @map("driver_id")
score Decimal @map("score")
delta Decimal @map("delta")
eventCode String @map("event_code")
description String @map("description")
tripId String? @map("trip_id")
recordedAt DateTime @default(now()) @map("recorded_at")
driver Driver @relation(fields: [driverId], references: [id], onDelete: Cascade)

@@map("safety_score_history")

@@schema("public")
}