Skip to content
Back to skills

Prisma Conventions

ASecurity

Prisma ORM conventions for this repo — schema/migration discipline, constraints Prisma can't express, and the @@map/@map gotcha that bites $queryRaw. Activate when writing or reviewing Prisma schema (schema.prisma), migrations, generated-client usage, or raw SQL through Prisma ($queryRaw/$executeRaw), or when debugging P2002 unique-constraint errors or "relation does not exist" at runtime.

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 2, 2026
ai-agentsgosqlexpressdebugginggitdatabase

Works with

  • cli

Security analysis

A100/100

Scanned September 2, 2026

npx -y skills add eric-sabe/engsys --skill prisma-conventions --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Prisma Conventions?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Prisma Conventions
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/eric-sabe-prisma-conventions/badge)](https://www.skillsdirectory.com/skills/eric-sabe-prisma-conventions)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: prisma-conventions
description: Prisma ORM conventions for this repo — schema/migration discipline, constraints Prisma can't express, and the @@map/@map gotcha that bites $queryRaw. Activate when writing or reviewing Prisma schema (schema.prisma), migrations, generated-client usage, or raw SQL through Prisma ($queryRaw/$executeRaw), or when debugging P2002 unique-constraint errors or "relation does not exist" at runtime.
---

# Prisma Conventions

Applies to any code touching Prisma in this repo — `schema.prisma`, migrations under
`prisma/migrations/`, the generated client, and raw SQL via `$queryRaw`/`$executeRaw`.

> Naturalize: confirm the schema path, datasource provider, and the database-package
> location in `CLAUDE.md`.

## Hard-won lessons

### Prisma can't express partial / conditional unique constraints
**Symptom:** You need uniqueness only under a condition (e.g. unique email *among
non-deleted rows*, or unique slug *per tenant where active*), but `@@unique` applies
unconditionally and rejects legitimate rows.
**Cause:** Prisma's schema DSL has no syntax for partial/filtered unique indexes —
`@@unique` maps to a plain `UNIQUE` constraint with no `WHERE`.
**Fix:** Hand-write the index in a migration —
`CREATE UNIQUE INDEX … ON … (…) WHERE …;` — and keep it out of the schema's
`@@unique`. Because Prisma doesn't model it, catch the violation in the service layer
by handling the **P2002** error code rather than relying on schema-level validation.

### `$queryRaw` uses DB names (@@map/@map), not Prisma model names
**Symptom:** Mocked/unit tests pass, but against a real database `$queryRaw` /
`$executeRaw` throws `relation "User" does not exist` (or a missing-column error).
**Cause:** Raw SQL **bypasses the ORM** and goes straight to Postgres. Prisma model
and field names are a client-side abstraction; the actual table/column names are the
`@@map`/`@map` values from the schema (e.g. model `User` → table `users`). Mocks
don't hit the DB, so they never reveal the mismatch.
**Fix:** In any raw SQL, reference the **mapped** table and column names (the
`@@map`/`@map` values), never the Prisma model/field names. Grep the schema for the
relevant `@@map`/`@map` before writing the query, and prefer an integration test that
hits a real database for any raw-SQL path.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.