Skip to content

D32 · Data gets columns; jsonb only where its shape truly varies

Accepted · 2026-10-09 · zuki

Decision: Every piece of data the system filters, joins, enforces a rule on, computes money from, or limits who may see is a real column with a type and constraints. No table gets a general-purpose metadata or extra jsonb column to hold new fields quickly. jsonb is used only where the data's shape truly varies:

  • Raw payloads from outside systems, kept as they arrived: GPS device data, ETLE scans, webhook bodies.
  • Snapshots and logs: the audit log's before and after data.
  • Configuration with a checked shape: organization settings and feature switches, such as allow_cross_pool_operations (#77).
  • Custom fields each client defines, once that is built as a feature in its own right, with field definitions and a check on the values.

Any jsonb column has a page saying what goes in it, and a check on its shape where Postgres can enforce one. A key that starts being filtered, joined or enforced is promoted to a column.

A behaviour that differs between clients is an organization setting, never a fork of the code or the schema. After cutover the schema only grows in steps that don't break a running app. A new column is added first; the data is copied and the app switched over; the old column is removed in a later release.

Why: The rules live in Postgres (D3), and Postgres can only enforce them on columns. Inside jsonb there are no required fields, no checks and no foreign keys. pnpm db:types gives apps/web no types for it, column privileges can't hide one key (D31), and a key no rule page describes falls outside the docs-first workflow (D27). The speed jsonb seems to save is small here. Migration files are editable until cutover (D11), and after it a nullable column is a one-line migration that Postgres applies instantly. Promoting years of loose jsonb to columns later costs far more.

Consequences: The Backend Engineer reviews every new jsonb column against this list in its pull request. The Docs Engineer gives each one a rule or a reference line saying what it holds. Custom fields per client wait until a client needs them, then arrive as their own decision and module. From cutover on, the migration runbook writes schema changes in the add, copy, remove order.