𝗜 𝘀𝗽𝗼𝘁𝘁𝗲𝗱 𝘁𝗵𝗲 𝘀𝗮𝗺𝗲 𝗱𝗮𝘁𝗮𝗯𝗮𝘀𝗲 𝗽𝗮𝘁𝘁𝗲𝗿𝗻 𝘁𝗵𝗿𝗲𝗲 𝘁𝗶𝗺𝗲𝘀 𝘁𝗼𝗱𝗮𝘆

I saw the same database shape three times in my code today.

First, I saw it with fees.

  • Fee (the parent: what a class owes)
  • FeePayment (the child: each individual payment)

Then, I saw it with assessments.

  • Assessment (the parent: the quiz details, date, and max score)
  • AssessmentResult (the child: each student score)

This structure prevents common mistakes.

If you do not use a parent-child pattern, you face these problems:

  • You repeat data. You copy the subject and date for every student row.
  • You create confusion. It is hard to know which rows belong to one event.
  • You clutter tables. You put header data into student rows where it does not belong.

Pattern recognition grows over time.

The first time you fix a structural problem, it is a single fix. The second time you see it, you recognize a pattern. The third time, you use it before you face the problem.

I am still building and testing edge cases. I am still learning.

Source: https://dev.to/johnstonkweku/i-spotted-the-same-database-design-pattern-three-times-in-my-own-code-today-4e4d