# Database Schema

> Model the data so the queries you will actually run stay honest as the product grows. Use when the user asks to schema.

- Skill: `delzarsolutionsllc/database-schema` (Agent Skill)
- Install (CLI): `npx skillmds@latest add delzarsolutionsllc/database-schema`
- Raw SKILL.md: https://api.skillmd.com/api/skills/delzarsolutionsllc/database-schema/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: delzarsolutionsllc (https://skillmd.com/u/delzarsolutionsllc)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/delzarsolutionsllc/database-schema

---


# Database Schema

The schema is the product. Migrations are how you tell the truth about it over time.

## Method
1. List the invariants: uniqueness, ownership, deletion, money, time.
2. Tables named for the noun. Columns that need an index are the ones in WHERE/JOIN you will actually run — prove it with a query, not a guess.
3. Foreign keys on by default. Soft-delete only when you can state the restore story.
4. NOT NULL unless you have a real unknown. Default values that encode business rules belong in code *and* the constraint.
5. Migrations are expand → backfill → contract. Never drop+rename in one step on a live table.

## Red flags
- ENUM columns you will regret
- JSON blobs for data you will query
- Missing unique constraints "because the app checks"
- TIMESTAMP without time zone

Output the DDL, the indexes, the down migration, and the query you expect to be fast.

