database-schema-design

Installation
SKILL.md

Database Schema Design

Overview

A good schema makes invalid data impossible and common queries fast. Push rules into constraints, derive indexes from real access patterns, and never ship a migration that locks or loses data.

Designing from scratch

  1. Entities and relationships. List nouns, their cardinality (1:1, 1:N, N:M) and ownership. N:M gets a join table.
  2. Keys. Surrogate primary key (bigint identity or UUIDv7). Natural uniqueness becomes a UNIQUE constraint, not the PK.
  3. Columns. Right type, NOT NULL by default, defaults where sensible. See the type table.
  4. Constraints. Foreign keys with explicit ON DELETE, UNIQUE, CHECK, enums or lookup tables for closed sets.
  5. Access patterns → indexes. Write the top 5-10 queries first; index their WHERE, JOIN and ORDER BY columns.
  6. Lifecycle. created_at, updated_at; soft delete only if the product needs restore or audit.
  7. Migration plan (below).

Reviewing an existing schema

Check every table against checklist.md. Read the queries in the code too: a schema is only "wrong" relative to how it is used.

Installs
2
GitHub Stars
4
First Seen
Oct 18, 2026