Install
openclaw skills install prisma-schema-analyzerAnalyze Prisma schemas for performance, relation design, index strategy, migration safety, and query optimization — audit schema.prisma for production readiness.
openclaw skills install prisma-schema-analyzerAnalyze Prisma schemas for performance issues, relation design problems, missing indexes, migration risks, and query optimization opportunities. Audit schema.prisma for production readiness and recommend improvements.
"Analyze my Prisma schema for issues"
"Check for missing indexes in my Prisma schema"
"Review Prisma relations for N+1 risks"
"Audit migration safety for my schema changes"
cat prisma/schema.prisma 2>/dev/null
find . -name "schema.prisma" 2>/dev/null
# Check migrations
ls prisma/migrations/ 2>/dev/null | tail -10
Field design:
@default values where applicable@updatedAt on models that need update tracking?) that should be requiredID strategy:
@id type: autoincrement vs cuid vs uuid@@id)Naming conventions:
@@map and @map for DB-native namingwhere clauses@@index)@@unique)createdAt / updatedAt for time-based queriesonDelete: Cascade vs SetNull vs Restrict)Review Prisma Client usage in codebase:
grep -rn "prisma\.\w\+\.find\|prisma\.\w\+\.create\|prisma\.\w\+\.update" src/ | head -30
grep -rn "include:" src/ | head -20
findUniquefindMany without selectfindMany without take/skipnpx prisma migrate diff --from-schema-datamodel prisma/schema.prisma --to-schema-datasource prisma/schema.prisma --script 2>/dev/null
## Prisma Schema Analysis
**Models:** 14 | **Relations:** 22 | **Indexes:** 8 | **Enums:** 5
### 🔴 Critical (2)
1. **Missing index on Order.userId** — prisma/schema.prisma:45
`userId String` without `@@index([userId])`
Orders table has FK queries on every page load
→ Add `@@index([userId])` to Order model
2. **Cascade delete on User → Orders** — prisma/schema.prisma:12
Deleting a user cascades to all orders (financial records!)
→ Change to `onDelete: Restrict` or `SetNull`
### 🟡 Improvements (4)
3. Missing `@updatedAt` on 8 models
4. Using String for `status` fields — use enum OrderStatus
5. Implicit many-to-many Tag-Post — add explicit for metadata
6. No composite index on `[userId, createdAt]` (common query pattern)
### 📊 Schema Metrics
- Average fields per model: 8.2
- Models with indexes: 6/14 (43%)
- Relations with explicit cascade: 4/22 (18%)
- Optional fields: 23 (review if all truly optional)
### ✅ Good Practices
- cuid() for all primary keys (distributed-safe)
- Enum types for status fields
- @map/@@ for Postgres naming conventions
- Proper DateTime fields with @default(now())