← All posts

How to Document Your Database Schema for a Team

By Varun Krishnan · Founder, dbdiagramr

Published · Updated · 5 min read

#database#documentation#tutorial

A practical guide to documenting your database schema so your team reads it: naming conventions, inline comments, and a one-page cheat sheet.

The short version

Document your schema in three layers: (1) name things well so they're self-documenting, (2) add inline column comments for the non-obvious stuff, (3) generate a one-page visual diagram that shows the relationships. Skip the 40-page Confluence page, nobody reads it.

Layer 1: Name things well

  • Tables: plural nouns, snake_case, order_items, not OrderItems.
  • Foreign keys: {table}_id, user_id, not userId.
  • Booleans: prefix with is_ or has_, is_active, has_paid.
  • Timestamps: created_at and updated_at.

Layer 2: Inline comments

PostgreSQL supports column-level comments. Use them for anything that isn't obvious from the name:

COMMENT ON COLUMN orders.status IS
  'pending | confirmed | shipped | delivered | cancelled. Never delete orders, set status to cancelled instead.';

What to comment: enum values, format requirements, business rules, deletion policies. What NOT to comment: id, created_at, obvious foreign keys.

Layer 3: Visual diagram

A one-page ER diagram replaces 40 pages of documentation. Use dbdiagramr, paste your connection string, get a visual schema in seconds. Show table names, primary keys, foreign key relationships, and non-obvious column types.

The one-page cheat sheet

Create a SCHEMA.md in your repo with table names, key columns, relationships, and a link to your visual diagram. Update it in the same PR that changes the schema.

Why schema docs go stale

A schema diagram is a snapshot of a moving target. A migration adds a column, someone renames a table, and the diagram is wrong while still looking authoritative. Three causes show up again and again:

  • Migrations do not update diagrams. Someone runs ALTER TABLE orders ADD COLUMN shipping_cost_cents integer; and no one remembers the diagram.
  • The diagram lives away from the code. A Confluence page or Figma file has no link to the migration that changed the schema.
  • Nobody owns it. Maintenance falls between frontend, backend, and operations, so it happens only when someone complains.

The failure is predictable: a stale diagram is worse than no diagram because people trust it. The fix is to make regeneration cheaper than editing the picture by hand.

Keep docs current in CI

Generate from the database or migrations, not from memory. A practical loop:

  1. Export the schema in CI with pg_dump --schema-only.
  2. Generate the diagram or SCHEMA.md from that dump.
  3. Commit the generated file, or fail the build when the committed copy differs.
pg_dump --schema-only "$DATABASE_URL" > schema.sql
# regenerate docs/schema.svg and SCHEMA.md from schema.sql
git diff --exit-code docs/schema.svg SCHEMA.md

The build check is the part that matters. A generation step without a diff check still depends on someone remembering to run it. Wire the check into the same pipeline that runs migrations, and update SCHEMA.md in the same pull request that changes the schema.

FAQ

Should I document every table?
No. Document the tables new engineers will touch, the ones with complex business logic, and the ones with non-obvious schemas.

Why do schema diagrams go stale?
Because they are static snapshots. Migrations change the database, but the diagram is not regenerated, and no one notices until someone trusts the wrong picture.

How often should I update the docs?
When you add or change a column. Put the update in your PR template as a checklist item.

What's the best tool for auto-generating schema docs?
dbdiagramr for visual diagrams. dbt's docs generate if you're on dbt.

Visualize your own database

Paste your PostgreSQL connection string and get an interactive ER diagram in under 10 seconds. No signup required.

Related guides

Try it on your database