agentleFS
jamestorrevillasjamestorrevillas/dev-skills/.github/skills/database-design/SKILL.md

database-design

Skill4 starsChanged 9 months agoMITView on GitHub

Use this skill when designing database schemas, choosing between SQL and NoSQL, optimizing queries, designing indexes, modeling relationships, working with vector databases, or planning data migrations. Trigger on keywords: database, schema, SQL, NoSQL, index, query optimization, data model, migration, ORM, PostgreSQL, MongoDB, Redis, vector database, N+1.

65 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use intelligent-routing, llm-application-dev and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SKB3002Skill

    intelligent-routing

    Automatic agent selection and intelligent task routing. Analyzes user requests and automatically selects the best specialist agent(s) without requiring explicit user mentions.

    Also in 5 projects that use this

  • pepebot-spaceSkill

    llm-application-dev

    Building applications with Large Language Models - prompt engineering, RAG patterns, and LLM integration. Use for AI-powered features, chatbots, or LLM-based automation.

    Also in 4 projects that use this

  • xenitV1Skill

    red-team-tactics

    Red team tactics principles based on MITRE ATT&CK. Attack phases, detection evasion, reporting.

    Also in 7 projects that use this

  • MoizIbnYousafSkill

    audit-library-health

    Use when checking the overall health of a skills library. Run doctor, validate, check for stale skills, and verify generated docs are in sync.

    Also in 3 projects that use this

  • MoizIbnYousafSkill

    browse-and-evaluate

    Use when exploring the ai-agent-skills catalog to find, compare, and evaluate skills before installing. Always use --fields to limit output size and --dry-run before committing to an install.

    Also in 3 projects that use this

  • SKB3002Skill

    nextjs-react-expert

    React and Next.js performance optimization from Vercel Engineering. Use when building React components, optimizing performance, eliminating waterfalls, reducing bundle size, reviewing code for performance issues, or implementing server/client-side optimizations.

    Also in 3 projects that use this

  • +5 more from MoizIbnYousaf

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 61 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every index slows down writes

    line 41
  2. Distinctive:

    Use cursor pagination for large tables or infinite scroll.

    line 70
  3. Distinctive:

    Hybrid: Use SQL as the source of truth, Redis for caching, Elasticsearch for search.

    line 84

“Common” is measured: kept by at least 6 in 10 of the 61 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Database Design

Schema Design Principles

  • Normalize first — eliminate redundancy, then denormalize only for proven performance needs
  • Name clearly — user_id not uid, created_at not ts
  • Every table needs — a primary key, created_at, updated_at
  • Soft deletes — add deleted_at instead of hard deleting rows you might need to recover

Relationship Patterns

RelationshipImplementation
One-to-OneForeign key on either table + UNIQUE constraint
One-to-ManyForeign key on the "many" side
Many-to-ManyJunction/pivot table with two foreign keys

Indexing Strategy

Rule: Index columns you filter, sort, or join on frequently.

-- Index for common query patterns
CREATE INDEX idx_orders_user_status ON orders(user_id, status);
CREATE INDEX idx_posts_created ON posts(created_at DESC);

-- Partial index for active records only
CREATE INDEX idx_active_users ON users(email) WHERE deleted_at IS NULL;

When NOT to Over-Index

  • Every index slows down writes
  • Index columns with low cardinality (boolean, status with 3 values) only if queries are very frequent
  • Monitor query performance, add indexes based on actual slow queries

Query Optimization

N+1 Query Problem

// BAD — N+1: 1 query for posts + N queries for each author
const posts = await Post.findAll()
for (const post of posts) {
  const author = await User.findById(post.userId) // N queries!
}

// GOOD — 2 queries total using JOIN or eager loading
const posts = await Post.findAll({ include: [{ model: User }] })

Pagination

-- Offset pagination (simple but slow for large offsets)
SELECT * FROM posts ORDER BY created_at DESC LIMIT 20 OFFSET 100;

-- Cursor pagination (fast for large datasets)
SELECT * FROM posts WHERE created_at < :cursor ORDER BY created_at DESC LIMIT 20;

Use cursor pagination for large tables or infinite scroll.


SQL vs NoSQL Cheatsheet

SQLNoSQL
ACID transactionsHigh write throughput
Complex queries, joinsFlexible/variable schema
Data integrity criticalHorizontal scale priority
Well-defined schemaUnstructured or nested data
PostgreSQL, MySQLMongoDB, DynamoDB, Cassandra

Hybrid: Use SQL as the source of truth, Redis for caching, Elasticsearch for search.


Vector Databases (AI Use Cases)

For semantic search, RAG, and embeddings:

DBBest For
pgvectorExisting PostgreSQL stack
PineconeManaged, production-scale
WeaviateMulti-modal, hybrid search
ChromaLocal dev and prototyping

Indexing Strategies

  • HNSW — best recall, higher memory usage
  • IVFFlat — lower memory, slightly lower recall
  • Product Quantization — memory-efficient for very large datasets

Migration Best Practices

  • Never drop columns in the same deploy as removing code that uses them — separate deploys
  • Backward compatible first — add new column → deploy new code → remove old column
  • Always test migrations on a copy of production data before running in prod
  • Zero-downtime migrations — use NOT NULL DEFAULT carefully, add constraints after backfill

Redis Use Cases

Use CasePattern
Session storageKey: session:{id}, TTL
Rate limitingIncrement counter with TTL
CachingKey: cache:{resource}:{id}, TTL
Pub/SubReal-time events between services
Job queueList with LPUSH/BRPOP
LeaderboardSorted Set (ZADD/ZRANGE)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.