用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mikailustuner/OmniRule --skill prisma-expert命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | prisma-expert |
| description | Prisma: Schema design patterns, Query optimization strategy, Transaction patterns, When to use what. |
| triggers | {"extensions":[".prisma"],"filenames":["schema.prisma"],"keywords":["Prisma","schema","migration","relation","query","select","include","connect"]} |
| auto_load_when | Editing Prisma schema or writing Prisma queries |
| agent | context-agent |
| tools | ["Read","Write","Bash"] |
Version: Prisma 7 | Focus: Schema, queries, transactions
When to use relations:
├── One-to-One: use @unique on child, NOT separate table
├── One-to-Many: parent has children array
├── Many-to-Many: implicit (array on both) OR explicit (join table)
└── Self-referential: use Optional for nullable
Indexes strategy:
├── Foreign keys: auto-indexed, add custom only if filtering
├── Composite: when querying multiple fields together
├── Partial: when filtering with same condition (WHERE active)
└── Unique: when field must be unique
Enums vs Strings:
├── Use enum: fixed values, won't change (Role.ADMIN vs "admin")
└── Use string: flexible, might expand (status field)
How to fetch related data?
├── Need ENTIRE related object → include
│ └── User with ALL posts: include: { posts: true }
│
├── Need SPECIFIC fields → select
│ └── User with post titles only: select: { posts: { select: { title: true } } }
│
├── Need nested depth → nested select/include
│ └── User → posts → comments: select: { posts: { include: { comments: true } } }
│
└── Count only → count or _count
└── User with post count: include: { _count: { select: { posts: true } } }
Query optimization order:
├── 1. Select only needed fields (select, not include)
├── 2. Add pagination (take/skip, cursor)
├── 3. Add indexes on WHERE/ORDER BY columns
├── 4. Use compound indexes for multi-column
├── 5. Check query plan with EXPLAIN
└── 6. Use $queryRaw only if ORM can't express
When to worry about performance:
├── Query returns >1000 rows → paginate
├── N+1 problem → use include or batch
├── Slow joins → denormalize or cache
└── Large JSON fields → separate table or index
When to use transactions:
├── Multiple writes that must succeed together
│ └── Order + OrderItems + Inventory update
│
├── Read-then-write (conditional)
│ └── Check balance, then deduct
│
├── Idempotency important
│ └── Same operation multiple times = same result
When NOT to use:
├── Single write → just write
├── Independent writes → parallel or sequential
└── Read-only operations → just read
When to use connection pooling:
├── Serverless functions (Vercel, Lambda)
├── High concurrency (100+ connections)
└── Long-running processes with many instances
How to choose:
├── Prisma Accelerate → managed, includes caching
├── PgBouncer → self-hosted, just pooling
├── Prisma Postgres → managed DB with native pooling
└── Direct connection → single instance, low traffic
When to migrate:
├── Development: migrate dev (creates migration)
├── Staging/Prod: migrate deploy (applies)
└── Never: migrate reset in production
Schema change workflow:
├── 1. Change schema.prisma
├── 2. Run migrate dev (creates .sql)
├── 3. Review migration SQL
├── 4. Push to repo
├── 5. CI runs migrate deploy
└── 6. Monitor for errors
When to implement soft delete:
├── Need audit trail
├── Can't permanently delete (compliance)
├── Need "trash" functionality
└── Related data should also be hidden
Implementation approaches:
├── Middleware: transform delete to update
├── Query filter: automatically filter deletedAt: null
└── Composite unique: allow multiple with different deletedAt
❌ findMany with no limit (fetch all rows)
✅ Always take + skip or cursor pagination
❌ Nested includes without selecting fields
✅ select specific fields in include to avoid over-fetching
❌ Running migrations in production without a rollback plan
✅ Test migration down script; use shadow DB for preview
❌ Raw SQL queries bypassing Prisma type safety
✅ Use Prisma Client; raw only for unsupported features with $queryRaw
❌ Multiple Prisma Client instances in serverless
✅ Singleton pattern with global caching in dev
| Operation | Prisma API | Note |
|---|---|---|
| Create | prisma.model.create | Returns created record |
| Update | prisma.model.update | Requires where |
| Upsert | prisma.model.upsert | create + update in one |
| Delete | prisma.model.delete | Soft-delete via deleted_at |
| Find many | findMany + take/skip | Never unbounded |
| Cursor page | findMany + cursor | For large datasets |
| Transaction | prisma.$transaction([]) | Atomic batch |
| Relation | include: { rel: true } | With select for perf |