AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Database Design

skill-jamestorrevillas-dev-skills-database-design · by jamestorrevillas

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.

No reviews yet
0 installs
25 views
0.0% view→install

Install

$ agentstack add skill-jamestorrevillas-dev-skills-database-design

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-jamestorrevillas-dev-skills-database-design)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
4mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Database Design? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Database Design

Schema Design Principles

  • Normalize first — eliminate redundancy, then denormalize only for proven performance needs
  • Name clearlyuser_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

| Relationship | Implementation | |---|---| | One-to-One | Foreign key on either table + UNIQUE constraint | | One-to-Many | Foreign key on the "many" side | | Many-to-Many | Junction/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

| SQL | NoSQL | |---|---| | ACID transactions | High write throughput | | Complex queries, joins | Flexible/variable schema | | Data integrity critical | Horizontal scale priority | | Well-defined schema | Unstructured or nested data | | PostgreSQL, MySQL | MongoDB, 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:

| DB | Best For | |---|---| | pgvector | Existing PostgreSQL stack | | Pinecone | Managed, production-scale | | Weaviate | Multi-modal, hybrid search | | Chroma | Local 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 Case | Pattern | |---|---| | Session storage | Key: session:{id}, TTL | | Rate limiting | Increment counter with TTL | | Caching | Key: cache:{resource}:{id}, TTL | | Pub/Sub | Real-time events between services | | Job queue | List with LPUSH/BRPOP | | Leaderboard | Sorted Set (ZADD/ZRANGE) |

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.