Model data around entities, relationships, constraints, and access patterns before writing application queries.
Course navigationPhase 07⌄
PostgreSQL Fundamentals
Use relational modeling and SQL deliberately: keys, constraints, joins, transactions, indexes, and query reasoning.
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.
Principles to keep while coding
Use transactions when multiple writes must succeed or fail as one unit.
Add indexes to support real query patterns, not every column indiscriminately.
Let database constraints defend invariants that must remain true regardless of application code.
Guided phase lab
Do these in order. Each step should end with evidence before the next one starts.
- 01
Model users, workspaces, membership, boards, lists, and tasks with primary/foreign keys on paper first.
- 02
Create a small local schema and insert data that exercises one-to-many and many-to-many relationships.
- 03
Write joins by hand and predict row counts before executing them.
- 04
Add unique/check/not-null constraints and intentionally violate each to observe database enforcement.
- 05
Wrap a multi-step change in a transaction and prove rollback preserves consistency.
- 06
Create an index for a real filter/sort pattern and compare EXPLAIN output conceptually.
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.
Failures you should know how to diagnose
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.
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.
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.
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.
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.
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
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
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
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
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
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
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
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
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
Guided Build Lab
Purpose Use relational modeling and SQL deliberately: keys, constraints, joins, transactions, indexes, and query reasoning.
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 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?
Mastery Capstone Lab
Integrate Phase 07 without following a transcript.
Exercises that increase independence
Model users, workspaces, membership, boards, lists, and tasks with primary/foreign keys on paper first.
Write joins by hand and predict row counts before executing them.
reproduce and diagnose — Treating IDs as the only integrity mechanism.
deliver A TaskFlow relational sketch plus SQL exercises that create, query, join, update, and constrain representative data.
Can read and write core SQL and Can choose keys and cardinality.
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/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.