database-design
Skill1.4k starsChanged 11 months agoMITView on GitHub
Designs database schemas, indexing strategies, query optimization, and migration patterns for SQL and NoSQL databases. Use when designing tables, optimizing queries, fixing N+1 problems, planning migrations, or when asked about database performance, normalization, ORMs, or data modeling.
42 other projects use a version of this.
Trending
More talk lately.thin dataabout the whole repository
Most recently taken up by
- vekzz-dev/opencode-skillstheir own version, first seen Oct 3, 2026
- hemapriyan-rk/claude-rigor-skillstheir own version, first seen Sep 26, 2026
- ZeroTokenClaw/agents-skillstheir own version, first seen Sep 21, 2026
- KbWen/agentic-ostheir own version, first seen Sep 10, 2026
- RealDougEubanks/ClaudeMarketplacetheir own version, first seen Sep 10, 2026
- VoDaiLocz/kilo-kit-mcptheir own version, first seen Aug 21, 2026
Who's talking about CloudAI-X/claude-workflow-v2
- @tom-doerr.bsky.social“https://github.com/CloudAI-X/claude-workflow-v2”Bluesky · Feb 21, 2026 · 1 likes
- LeszekKantorek/skills-library“Import: some development skills”GitHub · Oct 5, 2026
- sudosubin/agents.nix“codex-plugins.github.cloudai-x.claude-workflow-v2: init at 2.0.7”GitHub · Oct 4, 2026
- sudosubin/agents.nix“claude-code-plugins.github.cloudai-x.claude-workflow-v2: init at 2.0.7”GitHub · Oct 4, 2026
- sudosubin/agents.nix“claude-code-marketplaces.github.cloudai-x.claude-workflow-v2: init at 2.0.7”GitHub · Oct 4, 2026
The biggest 5 of 11 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 11
Talked about on GitHub and Bluesky (11 times).
On GitHub · 10
- Oct 5, 2026Import: some development skills — LeszekKantorek/skills-library0 reactions · 1 comment
- Oct 4, 2026codex-plugins.github.cloudai-x.claude-workflow-v2: init at 2.0.7 — sudosubin/agents.nix0 reactions
- Oct 4, 2026claude-code-plugins.github.cloudai-x.claude-workflow-v2: init at 2.0.7 — sudosubin/agents.nix0 reactions
- Oct 4, 2026claude-code-marketplaces.github.cloudai-x.claude-workflow-v2: init at 2.0.7 — sudosubin/agents.nix0 reactions
- Oct 3, 2026agent-skills.github.cloudai-x.claude-workflow-v2: 0-unstable-2026-06-02 → 2.0.7 — sudosubin/agents.nix0 reactions
5 more on GitHub
- Sep 26, 2026[Candidate] cloudai-x/claude-workflow-v2/skills/convex-backend - convex-backend — ProSkillsMD/proskills0 reactions · 2 comments
- Sep 26, 2026[Candidate] cloudai-x/claude-workflow-v2/skills/analyzing-projects - analyzing-projects — ProSkillsMD/proskills0 reactions · 1 comment
- Sep 26, 2026agent-skills.github.cloudai-x.claude-workflow-v2: init at 0-unstable-2026-06-02 — sudosubin/agents.nix0 reactions
- Apr 6, 2026Audit candidate: CloudAI-X/claude-workflow-v2 — xiaolai/nlpm0 reactions · 3 comments
- Jan 10, 2026New plugins: 41 skills from skills (low risk) — aiskillstore/marketplace0 reactions
On Bluesky · 1
- Feb 21, 2026https://github.com/CloudAI-X/claude-workflow-v2 — @tom-doerr.bsky.social1 likes and repost
Used with
Projects with it also use intelligent-routing, i18n-localization 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.
tiendatworkSkillintelligent-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 3 projects that use this
xfstudioSkilli18n-localization
Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.
Also in 5 projects that use this
xfstudioSkillbehavioral-modes
AI operational modes (brainstorm, implement, debug, review, teach, ship, orchestrate). Use to adapt behavior based on task type.
Also in 3 projects that use this
GenerativeAgentsSkillarchitecture-design
アーキテクチャ設計書を作成するための詳細ガイドとテンプレート。アーキテクチャ設計時にのみ使用。
Also in 8 projects that use this
- +8 more from xfstudio
Other versions42 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 42
- MoizIbnYousaf/ai-agent-skills★ 1.1ksame name
- KbWen/agentic-os★ 206same name
- thiientv/godmode★ 96same name
- KbWen/agent-virtual-office★ 35same name
- VoDaiLocz/kilo-kit-mcp★ 27same name
- krzysztofsurdy/code-virtuoso★ 22same name
- DauQuangThanh/hanoi-rainbow★ 17same name
- ishandutta2007/Awesome-Claude-Skills★ 15same name
- svngoku/coding-agents-skills★ 11same name
- xfstudio/skills★ 9same name
32 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository16 other files it gives its agents.
- skills/convex-backend/AGENTS.mdAGENTS.md
- skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- analyzing-projectsSkill
- convex-backendSkill
- designing-apisSkill
- designing-architectureSkill
- designing-testsSkill
- devops-infrastructureSkill
- error-handlingSkill
- managing-gitSkill
- optimizing-performanceSkill
- parallel-executionSkill
- security-patternsSkill
- vercel-react-best-practicesSkill
- web-design-guidelinesSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.
0
Common
Most of the 41 edited versions we read keep these.
1
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
- Distinctive: line 11
Skip: No database work involved in the current task
“Common” is measured: kept by at least 6 in 10 of the 41 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.
Files
Database Design
When to Load
- Trigger: Schema design, migrations, query optimization, indexing strategies, data modeling, N+1 fixes
- Skip: No database work involved in the current task
Database Design Workflow
Copy this checklist and track progress:
Database Design Progress:
- [ ] Step 1: Identify entities and relationships
- [ ] Step 2: Normalize schema (3NF minimum)
- [ ] Step 3: Evaluate denormalization needs
- [ ] Step 4: Design indexes for query patterns
- [ ] Step 5: Write and optimize critical queries
- [ ] Step 6: Plan migration strategy
- [ ] Step 7: Configure connection pooling
- [ ] Step 8: Validate against anti-patterns checklistSchema Design Principles
Normalization Forms
1NF: Atomic values, no repeating groups
2NF: 1NF + no partial dependencies (all non-key columns depend on full PK)
3NF: 2NF + no transitive dependencies (non-key columns don't depend on other non-key columns)-- WRONG: Unnormalized
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
customer_name TEXT,
customer_email TEXT, -- duplicated across orders
product1_name TEXT, -- repeating groups
product1_qty INT,
product2_name TEXT,
product2_qty INT
);
-- CORRECT: Normalized to 3NF
CREATE TABLE customers (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
customer_id INT REFERENCES customers(id),
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE order_items (
id SERIAL PRIMARY KEY,
order_id INT REFERENCES orders(id),
product_id INT REFERENCES products(id),
quantity INT NOT NULL CHECK (quantity > 0)
);When to Denormalize
Denormalize only when you have measured proof of performance issues:
-- Acceptable denormalization: precomputed counter to avoid COUNT(*)
ALTER TABLE posts ADD COLUMN comment_count INT DEFAULT 0;
-- Update via trigger or application code
CREATE FUNCTION update_comment_count() RETURNS TRIGGER AS $$
BEGIN
IF TG_OP = 'INSERT' THEN
UPDATE posts SET comment_count = comment_count + 1 WHERE id = NEW.post_id;
ELSIF TG_OP = 'DELETE' THEN
UPDATE posts SET comment_count = comment_count - 1 WHERE id = OLD.post_id;
END IF;
RETURN NULL;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER comments_count AFTER INSERT OR DELETE ON comments
FOR EACH ROW EXECUTE FUNCTION update_comment_count();Indexing Strategy
Index Types and When to Use
B-tree (default): Equality, range, sorting, LIKE 'prefix%'
Hash: Equality only (rarely better than B-tree)
GIN: Full-text search, JSONB, arrays
GiST: Geometry, range types, full-text
BRIN: Large tables with naturally ordered data (timestamps)Composite Indexes
-- Column order matters: leftmost prefix rule
CREATE INDEX idx_users_status_created ON users (status, created_at);
-- This index supports:
-- WHERE status = 'active' -- YES
-- WHERE status = 'active' AND created_at > '2024' -- YES
-- WHERE created_at > '2024' -- NO (skips first column)Partial and Covering Indexes
-- Partial index: only index rows matching condition
CREATE INDEX idx_orders_pending ON orders (created_at)
WHERE status = 'pending'; -- smaller index, faster lookups
-- Covering index: include columns to avoid table lookup
CREATE INDEX idx_users_email_covering ON users (email)
INCLUDE (name, avatar_url); -- index-only scan for profile lookupsIndex Anti-patterns
-- WRONG: Index on low-cardinality column alone
CREATE INDEX idx_users_active ON users (is_active); -- boolean = 2 values
-- WRONG: Too many indexes (slows writes)
-- Every INSERT/UPDATE must update ALL indexes
-- CORRECT: Composite index targeting actual queries
CREATE INDEX idx_users_active_created ON users (is_active, created_at DESC)
WHERE is_active = true;Query Optimization
Reading EXPLAIN Plans
EXPLAIN ANALYZE SELECT u.name, COUNT(o.id)
FROM users u
JOIN orders o ON o.user_id = u.id
WHERE u.status = 'active'
GROUP BY u.name;
-- Key things to look for:
-- Seq Scan -> missing index (on large tables)
-- Nested Loop -> fine for small sets, bad for large joins
-- Hash Join -> good for large equi-joins
-- Sort -> consider index to avoid sort
-- actual time -> real execution time
-- rows -> if estimated vs actual differ wildly, run ANALYZEN+1 Query Detection and Prevention
# WRONG: N+1 queries (1 query for users + N queries for orders)
users = db.query(User).all()
for user in users:
orders = db.query(Order).filter(Order.user_id == user.id).all() # N queries!
# CORRECT: Eager loading with SQLAlchemy
users = db.query(User).options(joinedload(User.orders)).all()
# CORRECT: Batch query
user_ids = [u.id for u in users]
orders = db.query(Order).filter(Order.user_id.in_(user_ids)).all()
orders_by_user = defaultdict(list)
for order in orders:
orders_by_user[order.user_id].append(order)// WRONG: N+1 with Prisma
const users = await prisma.user.findMany();
for (const user of users) {
const orders = await prisma.order.findMany({ where: { userId: user.id } }); // N+1!
}
// CORRECT: Include relation
const users = await prisma.user.findMany({
include: { orders: true },
});
// CORRECT: Batch with findMany + in
const userIds = users.map((u) => u.id);
const orders = await prisma.order.findMany({
where: { userId: { in: userIds } },
});Pagination
-- WRONG: OFFSET pagination (rescans all skipped rows)
SELECT * FROM posts ORDER BY created_at DESC LIMIT 20 OFFSET 10000;
-- CORRECT: Cursor-based pagination (keyset)
SELECT * FROM posts
WHERE (created_at, id) < ('2024-01-15T10:30:00Z', 12345)
ORDER BY created_at DESC, id DESC
LIMIT 20;Migration Patterns
Safe Migration Rules
1. Never rename a column in one step (add new, migrate data, drop old)
2. Never drop a column that's still read by running code
3. Add columns as nullable or with defaults
4. Create indexes CONCURRENTLY to avoid locking
5. Test rollback before deployingZero-Downtime Migration Example
-- Step 1: Add new column (brief ACCESS EXCLUSIVE lock — set lock_timeout and retry)
ALTER TABLE users ADD COLUMN display_name TEXT;
-- Step 2: Deploy code that writes to BOTH columns
-- Step 3: Backfill existing rows (do in batches)
UPDATE users SET display_name = name WHERE display_name IS NULL AND id BETWEEN 1 AND 10000;
-- Step 4: Deploy code that reads from new column
-- Step 5: Drop old column (after confirming no reads)
ALTER TABLE users DROP COLUMN name;Index Creation
-- WRONG: Blocks writes on the table
CREATE INDEX idx_orders_user ON orders (user_id);
-- CORRECT: Non-blocking (PostgreSQL)
CREATE INDEX CONCURRENTLY idx_orders_user ON orders (user_id);
-- Cannot run inside a transaction block: most migration tools wrap migrations
-- in one, so disable the transaction for this migrationConnection Pooling
Rule of thumb: connections = (CPU cores * 2) + disk spindles
For most apps: 10-20 connections per application instance# SQLAlchemy connection pool
engine = create_engine(
DATABASE_URL,
pool_size=10, # maintained connections
max_overflow=20, # extra connections under load
pool_timeout=30, # seconds to wait for connection
pool_recycle=1800, # recycle connections every 30 min
pool_pre_ping=True, # verify connection before use
)// Prisma datasource
// In schema.prisma:
// datasource db {
// provider = "postgresql"
// url = env("DATABASE_URL")
// }
// Connection limit via URL: ?connection_limit=10&pool_timeout=30ORM Best Practices
Select Only What You Need
# WRONG: Fetches all columns
users = db.query(User).all()
# CORRECT: Select specific columns
users = db.query(User.id, User.name).all()// WRONG: Fetches everything
const users = await prisma.user.findMany();
// CORRECT: Select specific fields
const users = await prisma.user.findMany({
select: { id: true, name: true, email: true },
});Bulk Operations
# WRONG: Individual inserts in a loop
for item in items:
db.add(Item(**item))
db.commit() # commit per item!
# CORRECT: Bulk insert
db.bulk_insert_mappings(Item, items)
db.commit()// WRONG: Sequential creates
for (const item of items) {
await prisma.item.create({ data: item });
}
// CORRECT: Batch create
await prisma.item.createMany({ data: items });
// CORRECT: Transaction for dependent operations
await prisma.user.create({
data: { ...userData, profile: { create: profileData } },
});NoSQL Design Patterns
Document Database (MongoDB)
// Design for access patterns, not normalization
// Embed when: 1:1, 1:few, data read together
// Reference when: 1:many, many:many, data grows unbounded
// WRONG: Normalizing in MongoDB like SQL
// users collection: { _id, name }
// addresses collection: { _id, userId, street } // requires joins
// CORRECT: Embed bounded, co-accessed data
{
_id: ObjectId("..."),
name: "Alice",
addresses: [
{ street: "123 Main St", city: "NYC", type: "home" },
{ street: "456 Work Ave", city: "NYC", type: "work" }
]
}
// CORRECT: Reference unbounded or independent data
// user: { _id, name }
// orders: { _id, userId, items: [...], total: 99.99 } // index orders.userIdKey-Value / Redis Patterns
# Cache-aside pattern
1. Check cache for key
2. If miss, query database
3. Store result in cache with TTL
4. Return result
# Cache invalidation
- TTL-based: SET key value EX 3600 (1 hour)
- Event-based: Delete key on write
- Write-through: Update cache on every writeCommon Anti-Patterns Summary
AVOID DO INSTEAD
-------------------------------------------------------------------
SELECT * SELECT specific columns
OFFSET pagination Cursor-based pagination
N+1 queries Eager load or batch queries
Indexing every column Index based on query patterns
UUID v4 as primary key UUID v7 or BIGSERIAL (better locality)
Storing money as FLOAT Use DECIMAL / BIGINT (cents)
No foreign keys "for speed" Use foreign keys (data integrity)
Giant migrations Small, reversible steps
No connection pooling Always pool connections
Premature denormalization Normalize first, denormalize with dataDoes 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
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.

