skip to content
07, 13 chapters
schema design
everything.design

schema design

keys, constraints, normal forms, and the patterns that keep data honest as it grows.

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