Database Audit banner
undeadlist undeadlist

Database Audit

Security community intermediate

Description

Analyze database layer for performance and correctness issues. Output to `.claude/audits/AUDIT_DB.md`.

Installation

Terminal
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: