Skip to content
Back to skills

Database

ASecurity

Database standards for PostgreSQL persistence and Redis caching. Use when designing schemas, writing migrations, optimizing queries, configuring Redis, or implementing cache invalidation.

  • 2 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added October 23, 2026
databasesgosqldatabasesecurityperformance

Works with

  • cli

Security analysis

A100/100

Pro scans all 9 files and shows the line behind each finding

Scanned October 23, 2026

npx -y skills add ndisisnd/cook --skill database --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Database?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Database
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ndisisnd-database/badge)](https://www.skillsdirectory.com/skills/ndisisnd-database)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: database
description: Database standards for PostgreSQL persistence and Redis caching. Use when designing schemas, writing migrations, optimizing queries, configuring Redis, or implementing cache invalidation.
metadata:
  triggers:
    files:
      - '**/*.entity.ts'
      - 'prisma/schema.prisma'
      - 'prisma/migrations/*/migration.sql'
      - '**/migrations/*.sql'
      - 'drizzle.config.ts'
      - 'drizzle/**/*.sql'
      - '**/redis.config.ts'
    keywords:
      - postgres
      - postgresql
      - prisma
      - TypeOrmModule
      - PrismaService
      - PostgresModule
      - redis
      - ttl
      - eviction
  targets: "PostgreSQL 16+ (17/18 features flagged) · Redis 7.2+ / Valkey 8+"
  last_reviewed: 2026-10-18
---

# Database Standards

Targets: PostgreSQL 16+ (17/18-only features are flagged) · Redis 7.2+ / Valkey 8+.
Supabase-specific rules (`auth.uid()`, `service_role`, Supavisor) live in `supabase`.

## Priority: P0 — PostgreSQL Correctness

### Schema & Access

- Isolate persistence behind repositories or database services; do not scatter raw database access across handlers.
- Enforce integrity in the database: primary keys, foreign keys, `NOT NULL`, `CHECK`, `UNIQUE`.
- Use `timestamptz`, `text`, `numeric` or integer minor units for money, and `GENERATED ALWAYS AS IDENTITY` or UUIDs for keys (see [postgresql-anti-patterns](refs/postgresql-anti-patterns.md)).

### Migrations

- Use explicit, version-controlled migrations for every schema change. ORM schema sync is dev-only:
  - TypeORM: never `synchronize: true` outside local dev.
  - Prisma: `prisma migrate deploy` in CI/prod; `migrate dev` and `db push` are dev-only.
  - Drizzle: `drizzle-kit generate` + `migrate` for shared environments; `drizzle-kit push` is prototyping-only.
- Destructive or renaming changes use expand-contract — the recipe is [postgresql-implementation](refs/postgresql-implementation.md).
- On live tables, set `lock_timeout`, build indexes `CONCURRENTLY`, and add constraints `NOT VALID` then `VALIDATE` — see the migration section of [postgresql-checklist](refs/postgresql-checklist.md).
- Generated ORM migrations do not capture Row-Level Security. Write RLS as explicit SQL.

### Queries & Performance

- Paginate every list query (keyset for deep pages).
- Index every hot filter, join, foreign-key, and RLS-predicate column.
- Use short transactions for multi-step mutations. Prevent N+1 with joins or batching.
- Project only the columns you need; no `SELECT *` in application queries.
- Behind a transaction-mode pooler (PgBouncer, Supavisor), do not rely on session state — see the pooling section of [postgresql-best-practices](refs/postgresql-best-practices.md).

## Priority: P0 — Redis Safety

### Data Design

- Redis/Valkey is a cache, queue, or coordination layer — never the sole source of truth for critical business data.
- Namespace keys with colons (`app:user:123`). Every non-permanent key needs a TTL; add TTL jitter on high-volume keys.
- Prefer hashes for field-addressable objects over large JSON blobs.

### Commands & Operations

- Never use `KEYS` in production; use `SCAN`. Use `UNLINK` for large keys. Bound every range read.
- Use pipelines for bulk work; Redis Functions (`FCALL`) or Lua for atomic multi-step logic.
- In production use ACL users, TLS, and disabled dangerous commands.

## Anti-Patterns

- Session-level `SET`, advisory locks, or SQL `PREPARE` through a transaction-mode pooler.

## References

Load only what the task requires:

PostgreSQL:
- [postgresql-implementation](refs/postgresql-implementation.md) — expand-contract migration recipe
- [postgresql-best-practices](refs/postgresql-best-practices.md) — indexing, pooling, RLS, partitioning, locking, diagnostics, PG17/18
- [postgresql-checklist](refs/postgresql-checklist.md) — review checklist incl. safe migrations
- [postgresql-anti-patterns](refs/postgresql-anti-patterns.md) — types, constructs, operations to avoid
- [sql-gotchas](refs/sql-gotchas.md) — `UPDATE ... FROM`, timezone, `NULL`, `ILIKE`, `JSONB`

Redis / Valkey:
- [redis-best-practices](refs/redis-best-practices.md) — caching, memory, commands, clients, security, licensing
- [redis-checklist](refs/redis-checklist.md) — Redis setup and cache review checklist

Files in this skill

  • SKILL.md4.2 KB
  • _INDEX.md1.6 KB
  • refs/postgresql-anti-patterns.md2.6 KB
  • refs/postgresql-best-practices.md4.3 KB
  • refs/postgresql-checklist.md2.8 KB
  • refs/postgresql-implementation.md1.4 KB
  • refs/redis-best-practices.md2.8 KB
  • refs/redis-checklist.md1.6 KB
  • refs/sql-gotchas.md1.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in databases →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.