Started work on writing explanation

This commit is contained in:
lucast committed 2026-11-20 19:28:58 +01:00
1 parent 985ff9b6f9
commit df49bfa6aa
2 files changed
+26

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
# Explanation
## Database Design
### ER Diagram
### Design Decisions
The database is structured around customers, their cars and the work orders created when those cars need repair.
I separated car brands and model into their own tables to avoid storing the same information and prevent inaccurate data.<br />
Each car references a model, which references a brand.<br />
So this disallows the Car table to have a row with a "Toyota M3" (aka, a BMW model on the Toyota brand), without having to add the model on the CarBrand table.
Invoice.workOrderId is both an id/PK and FK to only allow one invoice per work order.<br />
So the backend don't have to update WorkOrder.invoice.total on every update of WorkOrder while it's status == IN_PROGRESS, it is currently optional with the plan the backend only adds and keeps track of it after WorkOrder.status == DONE. Though this is not enforced by the DB.<br />
When a WorkOrder is done it should in a transaction both set WorkOrder.status = DONE and create the invoice.
All prices/rates is using an integer of "Øre" to avoid floating point precision problems, especially on larger amounts.
### PostgreSQL constraints.
I wanted to add the CHECK constraint in PostgreSQL.<br />
It is currently only possible in Prisma 8 without editing migration files.<br />
So for now I only have the one migration file with checks, the Prisma schema does not include these checks.
+1
View File
@@ -17,6 +17,7 @@ model WorkOrder {
mechanics WorkOrderToMechanic[] mechanics WorkOrderToMechanic[]
sparePart WorkOrderToSparePart[] sparePart WorkOrderToSparePart[]
// Add when status == DONE
invoice Invoice? invoice Invoice?
status WorkOrderStatus @default(OPEN) status WorkOrderStatus @default(OPEN)