Cancelled And Completed

Decide what you would do from the brief alone, including whether you would change anything at all. Everything below it is available, but the exercise stops working if you open it first.

The brief you were given

An Appointment row carries isConfirmed, isCancelled, isCompleted and isNoShow. A monthly report shows appointments that are both cancelled and completed. Finance asks which number is real.

The trap — the fix that looks like good design and is not

Adding assertConsistent(appointment) and calling it before every save, rejecting the impossible combinations. New bad rows stop appearing within a day, the fix is testable, and it needs no migration — which is why it is the one that ships. The four booleans remain the source of truth, so the rule about which combinations are legal now lives in a *different place* from the data it constrains and has to be kept in step by hand. Every new write path is a place someone forgets to call it, every bulk update and every admin script bypasses it, and the rows that are already wrong stay wrong. A validator makes an invalid state detected; a status field makes it impossible.

Read this even if you are confident. It is here rather than behind a button because it is the answer most teams actually ship, it passes review, and the cost of it does not arrive until the change after this one.