database-patterns

A reference guide to designing databases, including tables, relationships, indexes, data changes, and query performance.

In plain words
What is it for?
Use it when planning tables and relationships, choosing indexes, writing migrations, or improving database queries.
Why use it?
It helps avoid confusing schemas, slow queries, unsafe data changes, and inconsistent naming.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/subhansh-dev/agent-maxxing/database-patterns
Any agent
npx skills add subhansh-dev/agent-maxxing --skill database-patterns
Clone the repo
git clone --depth 1 https://github.com/subhansh-dev/agent-maxxing

Made for: Claude Code, Codex.

Per session 18 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 539 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00018 $0.00539
Opus 5 $0.00009 $0.00269
Sonnet 5 $0.00004 $0.00108
Haiku 4.5 $0.00002 $0.00054

Measured yesterday against content hash 2b924bcc43fc, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

database-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

engineering/database-patterns/SKILL.md · 78 lines

How it starts

The opening of the file, as written. The whole thing — 78 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Database Patterns

Schema Design

Naming

  • Tables: plural, snake_case (users, order_items)
  • Columns: snake_case (created_at, user_id)
  • Primary keys: id (auto-increment or UUID)
  • Foreign keys: <table>_id (user_id, order_id)
  • Timestamps: created_at, updated_at, deleted_at

Data Types

  • Strings: VARCHAR(n) for known max, TEXT for unlimited
  • Numbers: INTEGER for whole numbers, DECIMAL(p,s) for money
  • Booleans: BOOLEAN or TINYINT(1)
  • Dates: TIMESTAMP for date+time, DATE for date only
  • JSON: JSONB (PostgreSQL) for flexible structure

Relationships

  • One-to-many: foreign key on the many side
  • Many-to-many: junction table
  • One-to-one: foreign key with unique constraint

Indexing

When to Index

  • Columns used in WHERE clauses
  • Columns used in JOIN conditions
  • Columns used in ORDER BY
  • Columns with high cardinality (many unique values)

When NOT to Index

  • Small tables (< 1000 rows)
  • Columns with low cardinality (boolean, status)
  • Columns that are frequently updated
  • Tables with heavy write loads

Index Types

  • B-tree: default, good for most queries
  • Hash: exact match only, very fast
  • GIN: full-text search, JSON queries
  • Partial: index with WHERE clause

Migrations

Rules

  • Every migration must be reversible
  • Never modify a deployed migration
  • Add columns as nullable first, then backfill
  • Create index CONCURRENTLY in production
  • Test migrations on a copy of production data

Safe Migration Pattern

-- Step 1: Add nullable column
ALTER TABLE users ADD COLUMN bio TEXT;

-- Step 2: Backfill
UPDATE users SET bio = '' WHERE bio IS NULL;

-- Step 3: Add NOT NULL constraint
ALTER TABLE users ALTER COLUMN bio SET NOT NULL;

Query Optimization

  • Use EXPLAIN ANALYZE to check query plans
  • Avoid SELECT * — select only needed columns
  • Use LIMIT for large result sets
  • Batch inserts instead of single inserts
  • Use connection pooling
  • Avoid N+1 queries — use JOINs or eager loading

Read the full file on GitHub · 78 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 78 lines · 18 tokens per session scan A 2b924bcc43fc

Subscribe to this mod's changes

database-patterns is a skill published in the GitHub repository subhansh-dev/agent-maxxing (2 stars, last pushed 1mo ago), licensed MIT. It adds 18 tokens to every session and 539 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.