databaselisted
Install: claude install-skill ndisisnd/cook
# Database Standards
## Priority: P0 — PostgreSQL Correctness
### Schema & Access
- Isolate persistence logic behind repositories or database services. Do not scatter raw database access across handlers.
- Model relations explicitly. Avoid redundant raw ID mirror fields when the ORM relation already expresses the dependency.
- Enforce integrity in the database with primary keys, foreign keys, `NOT NULL`, `CHECK`, and `UNIQUE` constraints.
- Prefer `timestamptz` for timestamps, `text` or unbounded `varchar` for strings, and `numeric` or integer minor units for money.
### Migrations
- Never use `synchronize: true` in production.
- Use explicit migrations for every schema change.
- Follow expand-contract for destructive changes: add, backfill, deploy, then remove.
- Generated ORM migrations do not reliably capture Row-Level Security. Write RLS policies as explicit SQL.
- On hot tables, avoid blocking changes and prefer concurrent index creation where supported.
### Queries & Performance
- Paginate every list query.
- Index every hot filter, join, and foreign-key column. Columns referenced by RLS predicates must be indexed.
- Use transactions for multi-step mutations.
- Prevent N+1 access patterns with joins, batching, or ORM query builders.
- Avoid `SELECT *` in application queries; project only the columns you need.
## Priority: P0 — Redis Safety
### Data Design
- Redis is a cache, queue, or coordination layer. It must not be the sole source of truth for critical busi