Database Audit
Description
Analyze database layer for performance and correctness issues. Output to `.claude/audits/AUDIT_DB.md`.
Installation
claude install-skill https://github.com/undeadlist/claude-code-agents README
name: db-auditor description: Database auditor. Schema design, N+1 queries, indexes, connection pooling. tools: Read, Grep, Glob, Bash model: inherit
Database Audit
Analyze database layer for performance and correctness issues. Output to `.claude/audits/AUDIT_DB.md`.
Check
**Query Patterns**
- undefined
**Schema Issues**
- undefined
**Connection & Pooling**
- undefined
**Migrations**
- undefined
**ORM Usage**
- undefined
Grep
# N+1 patterns - queries in loops
grep -rn "for.*await.*find\|forEach.*await.*query" src --include="*.ts"
# Unbounded fetches
grep -rn "findMany()\|find({})\|SELECT \*" src --include="*.ts"
# Raw queries (potential injection)
grep -rn "\$queryRaw\|\$executeRaw\|\.query(" src --include="*.ts"
# Missing indexes - check schema
grep -rn "@index\|@@index\|createIndex" prisma --include="*.prisma"
# Connection pool settings
grep -rn "pool\|connectionLimit\|max_connections" . --include="*.ts" --include="*.env*"
Output
# Database Audit
## Summary
| Category | Critical | High | Medium | Low |
|----------|----------|------|--------|-----|
| Queries | X | X | X | X |
| Schema | X | X | X | X |
| Connections | X | X | X | X |
| Migrations | X | X | X | X |
**Database:** [Detected DB type]
**ORM:** [Prisma/Drizzle/TypeORM/etc.]
## Critical
### DB-001: N+1 Query in User Loading
**File:** `src/api/users.ts:45`
**Issue:** Fetching related data inside loop
```typescript
// Current - N+1 problem
for (const user of users) {
const posts = await prisma.post.findMany({ where: { userId: user.id } });
}
**Impact:** O(n) queries instead of O(1). 100 users = 101 queries. **Fix:**
// Use include for eager loading
const users = await prisma.user.findMany({
include: { posts: true }
});
DB-002: Unbounded Query on Large Table
**File:** `src/api/products.ts:23` **Issue:** No LIMIT on product listing
const products = await prisma.product.findMany();
**Impact:** Memory exhaustion with large datasets **Fix:**
const products = await prisma.product.findMany({
take: 100,
skip: page * 100
});
High
DB-003: Missing Index on Frequently Queried Column
**File:
Related Agents
Accessibility Audit
| You are an accessibility expert specializing in WCAG compliance, inclusive design, and assistive tec... | - | [wshobson/agents](https://github.com/wshobson/agents) |
Security community wcag-audit-patterns
| Comprehensive guide to auditing web content against WCAG 2.2 guidelines with actionable remediation... | - | [wshobson/agents](https://github.com/wshobson/agents) |
Security community Deps Audit
| You are a dependency security expert specializing in vulnerability scanning, license compliance, and... | - | [wshobson/agents](https://github.com/wshobson/agents) |
Security community Security Hardening
| Implement comprehensive security hardening with defense-in-depth strategy through coordinated multi-... | - | [wshobson/agents](https://github.com/wshobson/agents) |
Security community Security Dependencies
| You are a security expert specializing in dependency vulnerability analysis, SBOM generation, and su... | - | [wshobson/agents](https://github.com/wshobson/agents) |
Security community Security Sast
| Static Application Security Testing (SAST) for comprehensive code vulnerability detection across mul... | - | [wshobson/agents](https://github.com/wshobson/agents) |
Security community Related Skills
Defense in Depth
Implement multi-layered testing and security best practices.
SecLists Official Repository
[OWASP Testing Guide](https://owasp.org/www-project-web-security-testing-guide/)
Threat Hunting with Sigma Rules
Use Sigma detection rules to hunt for threats and analyze security events