Files
car-workshop/Explanation.md
T

1.4 KiB

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.