15 patterns · 78 working examples
When several tables look almost the same, they should be one table with a "type" label — stop the sprawl before it starts, not after.
15 patterns · 78 working examples
These aren't chapter titles — each one is an enforced rule your AI builds against. And the patterns don't just teach the shape: the working examples are real code that lands in your project.
The exact order foundational tables and functions have to migrate in
Wiring cross-table metadata and search without a bespoke join per table
Choosing between lifecycle status, workflow status, and priority without enum sprawl
A consistent shape for the flexible JSON metadata attached to any row
Keeping denormalized counts from silently going stale after a delete
Deciding whether a linked record's display fields update live or freeze
Keeping rollup counters trustworthy without opening them to app-level writes
When one self-referencing table beats a table per hierarchy level
Before adding a new table, checking whether an existing one already fits
Knowing when a JSONB field has earned its own typed column
Choosing between a typed foreign key and a polymorphic attachment
Modeling projects, tasks, and subtasks without a table sprawl per level
The canonical name every 'form', 'log', or 'document' table should map to
So a retried operation never runs twice
Wiring a tenant to one of several swappable outside vendors, cleanly
A database that looks fine at 10 tables and is a full rewrite at 40.