Course navigationPhase 07
Volume 03 · Phase 07

PostgreSQL Fundamentals

Use relational modeling and SQL deliberately: keys, constraints, joins, transactions, indexes, and query reasoning.

13lessons + labs
7klesson words
6source references
What you will ship

Phase outcome and project increment

Learning outcome

Use relational modeling and SQL deliberately: keys, constraints, joins, transactions, indexes, and query reasoning.

Concrete deliverable

A TaskFlow relational sketch plus SQL exercises that create, query, join, update, and constrain representative data.

Figure 7.1 — Where this phase lives in TaskFlow
Business invariant
table design
key/constraint
SQL query
query plan/index
transaction
durable rows
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

Model data around entities, relationships, constraints, and access patterns before writing application queries.

02

Use transactions when multiple writes must succeed or fail as one unit.

03

Add indexes to support real query patterns, not every column indiscriminately.

04

Let database constraints defend invariants that must remain true regardless of application code.

Code-along path

Guided phase lab

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

  1. 01

    Model users, workspaces, membership, boards, lists, and tasks with primary/foreign keys on paper first.

  2. 02

    Create a small local schema and insert data that exercises one-to-many and many-to-many relationships.

  3. 03

    Write joins by hand and predict row counts before executing them.

  4. 04

    Add unique/check/not-null constraints and intentionally violate each to observe database enforcement.

  5. 05

    Wrap a multi-step change in a transaction and prove rollback preserves consistency.

  6. 06

    Create an index for a real filter/sort pattern and compare EXPLAIN output conceptually.

TerminalVerification commands
psql --version
psql -h 127.0.0.1 -U <user> -d <db>

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

Treating IDs as the only integrity mechanism

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

Failure drill 2

Missing composite uniqueness on membership-like tables

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

Failure drill 3

N+1 query patterns hidden by application loops

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

Failure drill 4

Adding indexes without understanding query patterns

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

Relational Database Mental Model

FULL_STACK_DEVELOPER_2026_COMPLETE - Phase 07 Relational Database Mental Model VOLUME 03 - DATABASE ENGINEERING Relational Database Mental Model Durable state, tables, rows, schemas and inva

3 min
02

Data Types NULL and Constraints

FULL_STACK_DEVELOPER_2026_COMPLETE - Phase 07 Data Types, NULL and Constraints VOLUME 03 - DATABASE ENGINEERING Data Types, NULL and Constraints How PostgreSQL represents values and rejects

3 min
03

Keys Relationships and Joins

FULL_STACK_DEVELOPER_2026_COMPLETE - Phase 07 Keys, Relationships and Joins VOLUME 03 - DATABASE ENGINEERING Keys, Relationships and Joins Identity, referential integrity and relational read

3 min
04

SQL CRUD Filtering and Aggregates

FULL_STACK_DEVELOPER_2026_COMPLETE - Phase 07 SQL CRUD, Filtering and Aggregates VOLUME 03 - DATABASE ENGINEERING SQL CRUD, Filtering and Aggregates Read and change rows with deliberate quer

2 min
05

Transactions Indexes and Concurrency

FULL_STACK_DEVELOPER_2026_COMPLETE - Phase 07 Transactions, Indexes and Concurrency VOLUME 03 - DATABASE ENGINEERING Transactions, Indexes and Concurrency Atomic workflows, query access path

3 min
06

Normalization and Schema Evolution

FULL_STACK_DEVELOPER_2026_COMPLETE - Phase 07 Normalization and Schema Evolution VOLUME 03 - DATABASE ENGINEERING Normalization and Schema Evolution Design durable facts and change schemas w

3 min
07

TaskFlow Data Modeling Lab

FULL_STACK_DEVELOPER_2026_COMPLETE - Phase 07 TaskFlow Data Modeling Lab VOLUME 03 - DATABASE ENGINEERING TaskFlow Data Modeling Lab Translate product questions into tables, constraints, joi

3 min
08

SQL Safety Debugging and Practical Workflow

FULL_STACK_DEVELOPER_2026_COMPLETE - Phase 07 SQL Safety, Debugging and Practical Workflow VOLUME 03 - DATABASE ENGINEERING SQL Safety, Debugging and Practical Workflow Operate the database

3 min
09

Exercises and Phase Exit

FULL_STACK_DEVELOPER_2026_COMPLETE - Phase 07 Exercises and Phase Exit VOLUME 03 - DATABASE ENGINEERING Exercises and Phase Exit SQL practice, relational design drills and the Phase 08 readi

4 min
LAB

Guided Build Lab

Purpose Use relational modeling and SQL deliberately: keys, constraints, joins, transactions, indexes, and query reasoning.

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 07 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 07 without following a transcript.

2 min
Practice ladder

Exercises that increase independence

Guided

Model users, workspaces, membership, boards, lists, and tasks with primary/foreign keys on paper first.

Practice

Write joins by hand and predict row counts before executing them.

Debug

reproduce and diagnose — Treating IDs as the only integrity mechanism.

Independent

deliver A TaskFlow relational sketch plus SQL exercises that create, query, join, update, and constrain representative data.

Explain-back

Can read and write core SQL and Can choose keys and cardinality.

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 07's engineering goal?
02Which practice best matches Phase 07's engineering goal?
03Which practice best matches Phase 07's engineering goal?
04Which practice best matches Phase 07's engineering goal?
05You are working through the Phase 07 lab. Which next action is the most disciplined step?
06You are working through the Phase 07 lab. Which next action is the most disciplined step?
07You are working through the Phase 07 lab. Which next action is the most disciplined step?
08You are working through the Phase 07 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/SQL_Practice/00_practice_schema.sql
-- Phase 07 practice schema - not the final TaskFlow production schema.

CREATE TABLE practice_projects (
  id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  name text NOT NULL UNIQUE,
  created_at timestamptz NOT NULL DEFAULT now()
);

CREATE TABLE practice_tasks (
  id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  project_id bigint NOT NULL REFERENCES practice_projects(id),
  title text NOT NULL,
  completed boolean NOT NULL DEFAULT false,
  priority smallint NOT NULL DEFAULT 2 CHECK (priority BETWEEN 1 AND 3),
  due_at timestamptz,
  created_at timestamptz NOT NULL DEFAULT now(),
  CONSTRAINT practice_tasks_title_not_blank CHECK (length(btrim(title)) > 0)
);

CREATE INDEX practice_tasks_project_completed_idx
reference/SQL_Practice/01_seed_and_crud.sql
INSERT INTO practice_projects (name)
VALUES ('Course'), ('Portfolio')
RETURNING id, name;

INSERT INTO practice_tasks (project_id, title, priority)
VALUES
  (1, 'Learn relational modeling', 1),
  (1, 'Practice joins', 2),
  (2, 'Build portfolio project', 1)
RETURNING id, project_id, title, priority;

SELECT id, title, completed, priority
FROM practice_tasks
ORDER BY id;

UPDATE practice_tasks
SET completed = true
WHERE id = 1
RETURNING id, title, completed;
reference/SQL_Practice/02_queries_and_joins.sql
SELECT
  t.id,
  t.title,
  t.priority,
  p.name AS project_name
FROM practice_tasks AS t
JOIN practice_projects AS p ON p.id = t.project_id
WHERE t.completed = false
ORDER BY t.priority, t.created_at;

SELECT
  p.id,
  p.name,
  count(t.id) FILTER (WHERE t.completed = false) AS open_tasks,
  count(t.id) FILTER (WHERE t.completed = true) AS done_tasks
FROM practice_projects AS p
LEFT JOIN practice_tasks AS t ON t.project_id = p.id
GROUP BY p.id, p.name
ORDER BY p.name;
reference/SQL_Practice/03_transaction_practice.sql
BEGIN;

UPDATE practice_tasks
SET completed = true
WHERE id = 2
RETURNING id, title, completed;

-- Use COMMIT when the complete workflow is correct.
-- Use ROLLBACK while practicing if you want to discard the change.
ROLLBACK;
reference/SQL_Practice/04_cleanup.sql
DROP TABLE IF EXISTS practice_tasks;
DROP TABLE IF EXISTS practice_projects;
reference/SQL_Practice/README.txt
Phase 07 SQL Practice

These scripts are educational examples for PostgreSQL fundamentals.
They are intentionally not the final TaskFlow schema.

Suggested order once you have a PostgreSQL database in Phase 08:
1. 00_practice_schema.sql
2. 01_seed_and_crud.sql
3. 02_queries_and_joins.sql
4. 03_transaction_practice.sql
5. 04_cleanup.sql (only when you intentionally want to remove the practice tables)

Do not run destructive SQL against a database you have not verified.