Designing the data
Last updated
Code can be rewritten in a week; data lasts for years. What Pila stores, how its pieces connect and what it deliberately doesn't keep are some of the hardest decisions to change later. In this lesson you'll build Pila's data model entity by entity, find a field the user stories need, and learn why the best data to protect is the data you never collected.
By the end of this lesson you can
- Describe a data model with entities, attributes and relationships
- Turn user stories into the fields a model needs
- Explain why storing less data is part of good design
Things, details and links
A data model describes what a system remembers. It has three kinds of piece:
- Entities: the kinds of thing it keeps. For Pila: queue days, tickets, calls and staff.
- Attributes: the details of each. A ticket has a number, a phone, a priority, a status, a time taken.
- Relationships: how they connect, and how many of each.
Peter Chen's 1976 paper introduced the entity-relationship diagram for drawing them. Today the same model is often drawn as a UML class diagram: each entity a class, with its attributes listed under its name, and each relationship an association, a line with its multiplicity at each end, how many of that class take part.
- A QueueDay (date, opening and closing times, limit) has 0 to 60 Tickets; each ticket belongs to exactly 1 day.
- A Ticket (number, phone, which may be empty, priority, status, time taken) is called in 0 or more Calls (zero if the patient never came, more than once if they were skipped and called again); each call is of exactly 1 ticket.
- A Staff member (name, password hash) makes 0 or more calls; each call is made by exactly 1 staff member.
1 exactly one, 0..* any number, 0..60 up to 60). A ▸ shows which way to read an association’s name.There are no ids in the drawing yet: keys are a database detail, added in the next step. The "how many" at each end of a line matters. "A ticket is called zero or more times" is a decision: it lets staff skip a patient who isn't there and call them again later, which the counter wireframe in lesson 3.7 needed.
Tables and keys
In a relational database each entity usually becomes a table, each attribute a column, and each thing a row. Every row needs a key that identifies it; relationships are kept by storing one row's key in another row.
| Table | Columns | Links to |
|---|---|---|
| queue_day | date (the key), opens, closes, limit | |
| ticket | id (the key), day, number, phone (may be empty), priority, status, taken_at | queue_day, by its date |
| call | id (the key), ticket, called_at, staff | ticket, by its id; staff, by its id |
| staff | id (the key), name, password hash |
The ticket's id and its queue number aren't the same: numbers start again at 1 each day, but ids never repeat. Using the number as the key would have made yesterday's 38 and today's 38 the same row.
What the stories need
Every attribute should be there because a story or requirement needs it, and every story's data should have somewhere to live. Go through Pila's stories from lesson 3.P and check each candidate field.
0 of 7 placed right
Ticket: priority (senior, pregnant, or none)
Ticket: status (waiting, called, done, cancelled)
Ticket: patient’s birthday
Ticket: reason for the visit
Ticket: phone
Queue day: numbers given so far
Call: called at (time)
What not to store
The Data Privacy Act of 2012 says personal information should be collected for a declared purpose, be no more than that purpose needs, and be kept only as long as needed (Section 11, in plain words; this isn't legal advice). Design is where that becomes real: a field that doesn't exist can't leak.
For Pila, that means:
- Phone numbers, but not names. Replies need the phone; nothing needs the name. (Staff sign-in needs staff names, which is different data, about staff.)
- No health information at all. The reason for a visit stays between the patient and the midwife.
- Deleted after 30 days. The monthly report needs counts and times, not phone numbers, so tickets lose their phone number when the month's report is done.
Lesson 9.2 returns to this as privacy by design. And remember lesson 4.1: data is hard to change later. Adding a field next year is a migration; removing one that leaked is far worse.
Spot the trap: “in case it's useful”
Kap. Ernesto suggests Pila ask every patient for their full name, address, birthday and medical history when they take a number. “The barangay could use it for planning. It’s free to collect, since we’re building it anyway.”
What happens if…
Check what you learned
Sources
Every claim on this page comes from these sources: the standard, the founding text of a method, a study, or the official record of a project, from the body that publishes it. Industry reports are labelled as such.
- IEEE Computer Society: SWEBOK Guide, version 4.0 (2024): data design and data models in software design
- Republic Act No. 10173, the Data Privacy Act of 2012: personal information collected only for a declared purpose, and kept no longer than needed (Section 11)
- Peter Chen, “The Entity-Relationship Model: Toward a Unified View of Data”, ACM Transactions on Database Systems (1976): where entity-relationship diagrams began
- Object Management Group: Unified Modeling Language (UML) 2.5.1: class diagrams: classes, attributes, associations and multiplicities