07, 13 chapters
schema design
everything.design
schema design
keys, constraints, normal forms, and the patterns that keep data honest as it grows.
- 07.01from requirements to tablesentities, relationships, one-to-many and many-to-many. drawing the shop before creating it.
- 07.02primary keys, natural and surrogatewhat makes a row itself. composite keys, and the email address that changed.
- 07.03NOT NULL, CHECK and UNIQUErules the database enforces so your app doesn't have to remember, plus NULLS NOT DISTINCT.
- 07.04foreign keysreferences between tables. CASCADE, SET NULL, DEFERRABLE, and the index postgres doesn't create for you.
- 07.05functional dependencieswhat determines what. the bit of math that decides your keys and your normal forms.
- 07.06normal forms, 1NF to BCNFone fact, one place. update, insert and delete anomalies, and the decomposition that cures them.
- 07.07denormalizing on purposecounters, snapshots and copies you choose to keep, and the trigger that keeps them honest.
- 07.08storing treesadjacency list, ltree paths, closure tables. pick the shape by the queries you'll run.
- 07.09history, audit and soft deletedeleted_at, history tables, and what 'as of last tuesday' costs you.
- 07.10time ranges and temporal keyspostgres 18+exclusion constraints for no double booking, and WITHOUT OVERLAPS on primary and foreign keys.
- 07.11schema anti-patternsentity-attribute-value, polymorphic foreign keys, comma lists in a column, and the table called data.
- 07.12views and materialized viewsnamed queries, updatable views, and a cached result you refresh yourself.
- 07.13schemas, roles and row-level securitysearch_path, GRANT, and policies that filter rows per tenant without a single WHERE.