Normalize relationships enough to preserve correctness before optimizing for convenience.
Course navigationPhase 10⌄
Relational Data Modeling
Translate TaskFlow business relationships into a relational model that can enforce membership, ordering, labels, comments, ownership, and lifecycle rules.
Phase outcome and project increment
Learning outcome
Translate TaskFlow business relationships into a relational model that can enforce membership, ordering, labels, comments, ownership, and lifecycle rules.
Concrete deliverable
A complete Prisma/ER model for TaskFlow core entities with keys, relation tables, uniqueness, and important indexes.
Principles to keep while coding
Choose cardinality intentionally: one-to-one, one-to-many, and many-to-many model different business rules.
Use unique constraints and foreign keys to encode invariants where the database can enforce them.
Design TaskFlow entities around actual workflows such as workspaces, members, boards, lists, tasks, comments, and labels.
Guided phase lab
Do these in order. Each step should end with evidence before the next one starts.
- 01
List TaskFlow nouns and separate entities from attributes and events.
- 02
Model workspace membership as an explicit relation carrying role/state rather than an array on User.
- 03
Model boards/lists/tasks and decide which parent IDs should be required.
- 04
Model labels through a join table and explain composite uniqueness.
- 05
Add comments and timestamps with intentional delete behavior.
- 06
Seed a small realistic graph and query it from several directions to validate the model.
pnpm exec prisma migrate dev --name taskflow-core-model
pnpm exec prisma studioPredict what each command proves before running it. A command is useful only when its output answers a question.
Failures you should know how to diagnose
JSON arrays replacing relational join tables without reason
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
Ambiguous cascade-delete behavior
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
Duplicate membership rows permitted
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
Using nullable foreign keys where the domain requires ownership
Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.
Lessons
The source chapters come first. Every phase now ends with a guided build, a debugging workshop, and an independent challenge so reading turns into transferable skill.
Entities Relationships Cardinality and Ownership
Entities, Relationships, Cardinality & Ownership Turn product language into relational structure Phase 10 - Relational Data Modeling Volume 03 - Database Engineering Architecture milestone P
Optionality Keys and Constraints
Optionality, Keys & Constraints Put invariants in the database instead of only in application code Phase 10 - Relational Data Modeling Volume 03 - Database Engineering Architecture milestone
Many to Many Membership and Composite Uniqueness
Many-to-Many Membership & Composite Uniqueness Model collaboration as a first-class relationship Phase 10 - Relational Data Modeling Volume 03 - Database Engineering Architecture milestone P
Enums Lookup Tables and State Modeling
Enums, Lookup Tables & State Modeling Choose the right representation for finite business states Phase 10 - Relational Data Modeling Volume 03 - Database Engineering Architecture milestone P
Deletion Referential Actions and Lifecycle
Deletion, Referential Actions & Lifecycle Design what happens when related data disappears Phase 10 - Relational Data Modeling Volume 03 - Database Engineering Architecture milestone Postgre
Indexes and Query Driven Design
Indexes & Query-Driven Design Design access paths from real application queries Phase 10 - Relational Data Modeling Volume 03 - Database Engineering Architecture milestone PostgreSQL + Prism
Normalization and Denormalization
Normalization & Denormalization Avoid duplicated truth without turning the schema into theory theater Phase 10 - Relational Data Modeling Volume 03 - Database Engineering Architecture milest
TaskFlow Production Data Model
TaskFlow Production Data Model Assemble the first coherent relational model used by later phases Phase 10 - Relational Data Modeling Volume 03 - Database Engineering Architecture milestone P
Migration Planning and Safe Schema Evolution
Migration Planning & Safe Schema Evolution Change durable data without treating migrations as generated noise Phase 10 - Relational Data Modeling Volume 03 - Database Engineering Architectur
Hands On Lab and Phase Exit
Hands-On Lab & Phase Exit Practice relational reasoning before persistent CRUD Phase 10 - Relational Data Modeling Volume 03 - Database Engineering Architecture milestone PostgreSQL + Prisma
Guided Build Lab
Purpose Translate TaskFlow business relationships into a relational model that can enforce membership, ordering, labels, comments, ownership, and lifecycle rules.
Debugging Workshop
Goal Learn to diagnose this phase's failures systematically instead of reinstalling packages, changing random configuration, or copying a fix without understanding it.
Phase Synthesis & Independent Challenge
Mission Rebuild the capability of Phase 10 without following the exact code line-by-line. The goal is transfer: can you use the ideas when the variable names, UI, or route shape changes?
Mastery Capstone Lab
Integrate Phase 10 without following a transcript.
Exercises that increase independence
List TaskFlow nouns and separate entities from attributes and events.
Model boards/lists/tasks and decide which parent IDs should be required.
reproduce and diagnose — JSON arrays replacing relational join tables without reason.
deliver A complete Prisma/ER model for TaskFlow core entities with keys, relation tables, uniqueness, and important indexes.
Can explain every cardinality and Can justify join tables.
Do not leave the phase only because you reached the bottom
Phase exit criteria
Scenario and concept quiz
These questions test engineering choices rather than whether you remember a lesson title.
Reference files
Attempt the work first. Use snapshots to compare a checkpoint, not as a substitute for understanding.
reference/TaskFlow_Data_Model/README.txt
TaskFlow Phase 10 relational model reference This snapshot is the teaching model used at the end of Phase 10. It is not a complete final enterprise schema. Later phases add features only when their requirements become concrete. Important service invariant: - Task.assigneeId references User. Service logic must verify that the assignee is a member of the task project's workspace. Prisma remains locked to 7.9.1 for this course.
reference/TaskFlow_Data_Model/modeling-checklist.md
# Relational modeling checklist - What durable business fact does this model represent? - What is its stable identity? - Which fields are required vs optional? - Which values must be unique? - What relationships exist and what is their cardinality? - Does the relationship carry its own metadata? - What happens when each parent is deleted? - Which invariants belong in database constraints? - Which rules require application/service context? - What high-value queries will need indexes? - Is any fact duplicated unnecessarily? - How will this schema evolve after data exists?
reference/TaskFlow_Data_Model/schema.prisma
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
moduleFormat = "cjs"
}
datasource db {
provider = "postgresql"
}
enum MembershipRole {
OWNER
ADMIN
MEMBER
}
enum TaskStatus {
TODO
IN_PROGRESS
DONE