ServerCRUD
Runbook
Troubleshooting and maintenance guide for the CRUD engine.
Common Issues
"Model or operation not supported"
Symptoms: HTTP 400/500 error with this message.
Diagnosis:
- Check model name matches
schema.prisma(case-sensitive) - Verify
prisma generatehas run
Resolution:
# Regenerate Prisma client
pnpm --filter @repo/crm-db db:core:generate
# Verify model exists
grep "^model" packages/crm/db/schema.prismaSlow Queries
Symptoms: findMany operations taking > 500ms.
Diagnosis:
- Check
crud_operation_durationhistogram - Check for missing indexes
- Verify query filters are indexed
Resolution:
-- Check indexes on a table
SELECT indexname, indexdef
FROM pg_indexes
WHERE tablename = 'contact';
-- Add index for common filter
CREATE INDEX idx_contact_org ON contact(org_id);Hooks Not Executing
Symptoms: Side-effects (emails, webhooks) not triggering.
Diagnosis:
- Check hook registration in
hooks.ts - Verify model/op matchers
- Check hook handler errors
Resolution:
// Debug hook execution
import { crudHooks } from "./hooks";
console.log("Registered hooks:", crudHooks.getRegistered());Maintenance
Adding a New Model
- Define model in
packages/crm/db/schema.prisma - Generate client:
pnpm --filter @repo/crm-db db:core:generate - Create Zod schemas in
crm/server/features/crud/schemas/ - Register routes using
createCrudRoutes:import { createCrudRoutes } from "@/features/crud/crud.routes"; export const myModelRoutes = createCrudRoutes({ model: "myModel", schemas: { ... }, }); - Add to router in
crm/server/routes/index.ts
Modifying Operation Pipeline
Warning: The shared pipeline in
features/shared/operation-pipeline.tsaffects all database operations.
Changes here require:
- Full regression testing
- Review by another engineer
- Deploy during maintenance window
Database Commands
# Push schema
pnpm --filter @repo/crm-db db:core:push
# Studio
pnpm --filter @repo/crm-db db:core:studio
# Generate migrations
pnpm --filter @repo/crm-db db:core:gen-migration
# Deploy migrations
pnpm --filter @repo/crm-db db:core:migrate