diff --git a/Explanation.md b/Explanation.md new file mode 100644 index 0000000..3e7a3c4 --- /dev/null +++ b/Explanation.md @@ -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.
+Each car references a model, which references a brand.
+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.
+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.
+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.
+It is currently only possible in Prisma 8 without editing migration files.
+So for now I only have the one migration file with checks, the Prisma schema does not include these checks. \ No newline at end of file diff --git a/prisma/models/workOrder.prisma b/prisma/models/workOrder.prisma index 8cb30d4..8755e96 100644 --- a/prisma/models/workOrder.prisma +++ b/prisma/models/workOrder.prisma @@ -17,6 +17,7 @@ model WorkOrder { mechanics WorkOrderToMechanic[] sparePart WorkOrderToSparePart[] + // Add when status == DONE invoice Invoice? status WorkOrderStatus @default(OPEN)