uup
This commit is contained in:
160
prisma/schema.prisma
Normal file
160
prisma/schema.prisma
Normal file
@@ -0,0 +1,160 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
// User model for authentication and access control
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
username String @unique
|
||||
email String @unique
|
||||
password String // hashed password
|
||||
status String @default("active") // "active" or "inactive"
|
||||
authLevel Int // 1=superadmin, 2=admin, 3=user
|
||||
createdDate DateTime @default(now())
|
||||
editDate DateTime @updatedAt
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
|
||||
// Customer model for vehicle owners
|
||||
model Customer {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
phone String?
|
||||
email String?
|
||||
address String?
|
||||
createdDate DateTime @default(now())
|
||||
updateDate DateTime @updatedAt
|
||||
|
||||
// Relationships
|
||||
vehicles Vehicle[]
|
||||
maintenanceVisits MaintenanceVisit[]
|
||||
|
||||
@@map("customers")
|
||||
}
|
||||
|
||||
// Vehicle model with comprehensive specifications
|
||||
model Vehicle {
|
||||
id Int @id @default(autoincrement())
|
||||
plateNumber String @unique
|
||||
bodyType String
|
||||
manufacturer String
|
||||
model String
|
||||
trim String?
|
||||
year Int
|
||||
transmission String // "Automatic" or "Manual"
|
||||
fuel String // "Gasoline", "Diesel", "Hybrid", "Mild Hybrid", "Electric"
|
||||
cylinders Int?
|
||||
engineDisplacement Float?
|
||||
useType String // "personal", "taxi", "apps", "loading", "travel"
|
||||
ownerId Int
|
||||
lastVisitDate DateTime?
|
||||
suggestedNextVisitDate DateTime?
|
||||
createdDate DateTime @default(now())
|
||||
updateDate DateTime @updatedAt
|
||||
|
||||
// Relationships
|
||||
owner Customer @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
maintenanceVisits MaintenanceVisit[]
|
||||
|
||||
@@map("vehicles")
|
||||
}
|
||||
|
||||
// Maintenance type model for categorizing maintenance services
|
||||
model MaintenanceType {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @unique
|
||||
description String?
|
||||
isActive Boolean @default(true)
|
||||
createdDate DateTime @default(now())
|
||||
updateDate DateTime @updatedAt
|
||||
|
||||
@@map("maintenance_types")
|
||||
}
|
||||
|
||||
// Car dataset model for storing vehicle manufacturers, models, and body types
|
||||
model CarDataset {
|
||||
id Int @id @default(autoincrement())
|
||||
manufacturer String
|
||||
model String
|
||||
bodyType String
|
||||
isActive Boolean @default(true)
|
||||
createdDate DateTime @default(now())
|
||||
updateDate DateTime @updatedAt
|
||||
|
||||
// Unique constraint to prevent duplicate manufacturer-model combinations
|
||||
@@unique([manufacturer, model])
|
||||
@@map("car_dataset")
|
||||
}
|
||||
|
||||
// Maintenance visit model for tracking service records
|
||||
model MaintenanceVisit {
|
||||
id Int @id @default(autoincrement())
|
||||
vehicleId Int
|
||||
customerId Int
|
||||
maintenanceJobs String // JSON field storing array of maintenance jobs: [{"typeId": 1, "job": "تغيير زيت المحرك", "notes": "..."}, ...]
|
||||
description String
|
||||
cost Float
|
||||
paymentStatus String @default("pending")
|
||||
kilometers Int
|
||||
visitDate DateTime @default(now())
|
||||
nextVisitDelay Int // months (1, 2, 3, or 4)
|
||||
createdDate DateTime @default(now())
|
||||
updateDate DateTime @updatedAt
|
||||
|
||||
// Relationships
|
||||
vehicle Vehicle @relation(fields: [vehicleId], references: [id], onDelete: Cascade)
|
||||
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
||||
income Income[]
|
||||
|
||||
@@map("maintenance_visits")
|
||||
}
|
||||
|
||||
// Expense model for business expense tracking
|
||||
model Expense {
|
||||
id Int @id @default(autoincrement())
|
||||
description String
|
||||
category String
|
||||
amount Float
|
||||
expenseDate DateTime @default(now())
|
||||
createdDate DateTime @default(now())
|
||||
updateDate DateTime @updatedAt
|
||||
|
||||
@@map("expenses")
|
||||
}
|
||||
|
||||
// Income model for revenue tracking from maintenance visits
|
||||
model Income {
|
||||
id Int @id @default(autoincrement())
|
||||
maintenanceVisitId Int
|
||||
amount Float
|
||||
incomeDate DateTime @default(now())
|
||||
createdDate DateTime @default(now())
|
||||
updateDate DateTime @updatedAt
|
||||
|
||||
// Relationships
|
||||
maintenanceVisit MaintenanceVisit @relation(fields: [maintenanceVisitId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@map("income")
|
||||
}
|
||||
|
||||
// Settings model for application configuration
|
||||
model Settings {
|
||||
id Int @id @default(autoincrement())
|
||||
key String @unique
|
||||
value String
|
||||
description String?
|
||||
createdDate DateTime @default(now())
|
||||
updateDate DateTime @updatedAt
|
||||
|
||||
@@map("settings")
|
||||
}
|
||||
Reference in New Issue
Block a user