# Database Schema Design

Schema discipline that makes data trustworthy.

## Rules

1. **The schema is the contract.** If a constraint exists in the domain, it exists in the schema. Not-null, unique, foreign key, check constraint — the database enforces what the business requires. Application code is the fallback, not the enforcer.

2. **Every table has a single primary key.** Surrogate integer or UUID. No composite primary keys. Composite uniqueness is a unique index, not a primary key.

3. **Migrations are forward-only.** Once deployed, a migration never changes. Fix it with another migration. Your migration history is your production history. Editing it is rewriting history.

4. **Null means unknown, not default.** If a value is required, make it not-null with a default. If it's genuinely optional, null is fine. But never use null as a magic value.

5. **Index for queries, not for structure.** Add indexes based on actual query patterns, not theoretical access paths. Profile first. Index second.

6. **No ORM magic in migrations.** Migrations are raw SQL. They run once, in order, against production. They must be explicit, reviewable, and reversible in intent.

## What This Replaces

Schema-as-suggestion and migration-as-afterthought. The database becomes the authoritative source of truth for data integrity.
