Dating-Safety App Tables and Relations¶
Run the Dating-Safety App Tables and Relations MicroSim Fullscreen
About This MicroSim¶
In this illustrative design, the dating-safety app keeps its data in five tables: members, scans, uploads, check_results and payments. Four foreign keys link them. Three of those links cascade, so deleting a parent row deletes its children. The link from members to payments sets the key to empty instead, so payment records survive.
Deleting one member reaches three other tables. That surprises most people the first time they see it drawn out. The column lists and delete rules here are an illustrative design, not the app's real schema.
Learning objective (Understand: explain): Explain, for each relation between five tables in the dating-safety app, which column is the foreign key and what happens to the child rows when a parent row is deleted.
How to Use¶
- Click any table to see its columns. PK marks the primary key and FK marks a foreign key.
- Click any arrow to see its foreign key, its relation ("one X has many Y") and its delete rule.
- Select members or scans, then press Delete this row. Red tables lose rows; the orange table keeps its rows with the key emptied.
- Press Check my understanding to answer five questions, one attempt each. A wrong answer highlights the arrow in question.
- Press Clear to reset the highlights.
Iframe Embed Code¶
You can add this MicroSim to any web page by adding this to your HTML:
<iframe src="https://arunbatchu.github.io/good-enough-engineering/sims/safety-app-table-relations/main.html"
height="574px"
width="100%"
scrolling="no"></iframe>
Lesson Plan¶
Grade Level¶
Adult professional (Good Enough Engineering)
Duration¶
10-15 minutes
Prerequisites¶
Table, row, column, primary key, UUID, foreign key, relation, and the cascade, refuse and set-to-empty delete rules, from the chapter sections before the diagram.
Activities¶
- Exploration (5 min): Click every table and every arrow. Say each relation out loud as "one X has many Y."
- Guided Practice (5 min): Delete a member, then clear and delete a scan. Compare which tables each one reaches.
- Assessment (5 min): Answer the five questions. Discuss which tables in your own app should cascade and which should keep rows.
Common Misconceptions¶
- Deleting a member always removes everything about them.
- A foreign key is just a label and the database doesn't check it.
- Every relation should cascade.
Assessment¶
- Answers 4 of 5 deletion questions correctly on the first attempt.
- Names the foreign key column for each of the four relations.
- Explains why payments set the key to empty instead of cascading.
References¶
- PostgreSQL documentation: Foreign keys - how ON DELETE CASCADE, RESTRICT and SET NULL behave.
- vis-network documentation - the graph library used to draw the tables.