Course navigationPhase 10
Volume 03 · Phase 10

Relational Data Modeling

Translate TaskFlow business relationships into a relational model that can enforce membership, ordering, labels, comments, ownership, and lifecycle rules.

14lessons + labs
5klesson words
3source references
What you will ship

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.

Figure 10.1 — Where this phase lives in TaskFlow
Business nouns
entities
relationships/cardinality
constraints
Prisma models
migration
seeded graph
Trace the flow left-to-right for implementation and right-to-left for debugging. At every arrow, ask what data crosses the boundary and what proves it is trustworthy.
Instructor mental model

Principles to keep while coding

01

Normalize relationships enough to preserve correctness before optimizing for convenience.

02

Choose cardinality intentionally: one-to-one, one-to-many, and many-to-many model different business rules.

03

Use unique constraints and foreign keys to encode invariants where the database can enforce them.

04

Design TaskFlow entities around actual workflows such as workspaces, members, boards, lists, tasks, comments, and labels.

Code-along path

Guided phase lab

Do these in order. Each step should end with evidence before the next one starts.

  1. 01

    List TaskFlow nouns and separate entities from attributes and events.

  2. 02

    Model workspace membership as an explicit relation carrying role/state rather than an array on User.

  3. 03

    Model boards/lists/tasks and decide which parent IDs should be required.

  4. 04

    Model labels through a join table and explain composite uniqueness.

  5. 05

    Add comments and timestamps with intentional delete behavior.

  6. 06

    Seed a small realistic graph and query it from several directions to validate the model.

TerminalVerification commands
pnpm exec prisma migrate dev --name taskflow-core-model
pnpm exec prisma studio

Predict what each command proves before running it. A command is useful only when its output answers a question.

Debugging studio

Failures you should know how to diagnose

Failure drill 1

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.

Failure drill 2

Ambiguous cascade-delete behavior

Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.

Failure drill 3

Duplicate membership rows permitted

Predict the symptom, capture evidence at the nearest boundary, change one variable, and verify the same reproduction after the fix.

Failure drill 4

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.

Watch-order style

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.

01

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

2 min
02

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

2 min
03

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

2 min
04

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

2 min
05

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

2 min
06

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

2 min
07

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

2 min
08

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

2 min
09

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

2 min
10

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

2 min
LAB

Guided Build Lab

Purpose Translate TaskFlow business relationships into a relational model that can enforce membership, ordering, labels, comments, ownership, and lifecycle rules.

3 min
LAB

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.

2 min
LAB

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?

2 min
LAB

Mastery Capstone Lab

Integrate Phase 10 without following a transcript.

2 min
Practice ladder

Exercises that increase independence

Guided

List TaskFlow nouns and separate entities from attributes and events.

Practice

Model boards/lists/tasks and decide which parent IDs should be required.

Debug

reproduce and diagnose — JSON arrays replacing relational join tables without reason.

Independent

deliver A complete Prisma/ER model for TaskFlow core entities with keys, relation tables, uniqueness, and important indexes.

Explain-back

Can explain every cardinality and Can justify join tables.

Mastery gate

Do not leave the phase only because you reached the bottom

Phase exit criteria

Knowledge check

Scenario and concept quiz

These questions test engineering choices rather than whether you remember a lesson title.

0/0 correct · 0/8 answered
01Which practice best matches Phase 10's engineering goal?
02Which practice best matches Phase 10's engineering goal?
03Which practice best matches Phase 10's engineering goal?
04Which practice best matches Phase 10's engineering goal?
05You are working through the Phase 10 lab. Which next action is the most disciplined step?
06You are working through the Phase 10 lab. Which next action is the most disciplined step?
07You are working through the Phase 10 lab. Which next action is the most disciplined step?
08You are working through the Phase 10 lab. Which next action is the most disciplined step?
Source snapshot

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