install
source · Clone the upstream repo
git clone https://github.com/Intense-Visions/harness-engineering
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/Intense-Visions/harness-engineering "$T" && mkdir -p ~/.claude/skills && cp -r "$T/agents/skills/codex/prisma-schema-design" ~/.claude/skills/intense-visions-harness-engineering-prisma-schema-design-0d0e17 && rm -rf "$T"
manifest:
agents/skills/codex/prisma-schema-design/SKILL.mdsource content
Prisma Schema Design
Design Prisma schemas with datasource, generator, models, field types, and field attributes
When to Use
- Creating a new Prisma project and defining the initial schema
- Adding new models or fields to an existing Prisma schema
- Choosing the correct field types, attributes, and defaults for a data model
- Configuring datasource (PostgreSQL, MySQL, SQLite) and generator blocks
Instructions
- Start every schema with a
block specifying the provider and connection string viadatasource
:env()
datasource db { provider = "postgresql" url = env("DATABASE_URL") }
- Add a
block for Prisma Client. Place it immediately after the datasource:generator
generator client { provider = "prisma-client-js" }
- Define models with PascalCase names. Every model must have exactly one
field or a@id
composite key:@@id
model User { id String @id @default(cuid()) email String @unique name String? role Role @default(USER) posts Post[] createdAt DateTime @default(now()) updatedAt DateTime @updatedAt }
-
Use the correct scalar types:
,String
,Int
,BigInt
,Float
,Decimal
,Boolean
,DateTime
,Json
. AppendBytes
for optional fields.? -
Apply field-level attributes in this order:
,@id
,@unique
,@default(...)
,@map("column_name")
.@db.VarChar(255) -
Use
to decouple Prisma model names from database table names when working with legacy databases.@@map("table_name") -
Use
for composite unique constraints and@@unique([fieldA, fieldB])
for composite indexes.@@index([fieldA, fieldB]) -
Define enums at the schema level and reference them as field types:
enum Role { USER ADMIN MODERATOR }
-
Use
for integer IDs,@default(autoincrement())
or@default(cuid())
for string IDs. Prefer@default(uuid())
unless your system requires UUID format.cuid() -
Add
to a@updatedAt
field to auto-set the timestamp on every update. Only oneDateTime
per model.@updatedAt
Details
Prisma schema is the single source of truth for your database structure and the generated TypeScript client. The schema file (
prisma/schema.prisma) is declarative and uses its own DSL.
Datasource providers:
postgresql, mysql, sqlite, sqlserver, mongodb, cockroachdb. Each provider supports a different subset of native types (e.g., @db.VarChar(255) for PostgreSQL, @db.Text for MySQL).
Native type annotations let you override the default database column type. Without them, Prisma maps scalar types to sensible defaults (e.g.,
String maps to text on PostgreSQL). Use @db.VarChar(n) when you need a length constraint at the database level.
Multi-file schemas are supported via the
prismaSchemaFolder preview feature. Split large schemas into multiple .prisma files within the prisma/schema/ directory.
Trade-offs:
IDs are shorter and URL-safe but not a standard format;cuid()
is universally recognized but longeruuid()
fields bypass Prisma's type system — validate JSON content at the application layer or use ZodJson
is evaluated at the database level;@default(now())
delegates to database functions@default(dbgenerated("gen_random_uuid()"))
preserves precision for financial data;Decimal
introduces IEEE 754 roundingFloat
Common mistakes:
- Forgetting
means the field stays at its initial value forever@updatedAt - Using
for IDs on tables that will exceed 2.1 billion rows — useInt
insteadBigInt - Not adding
on foreign key fields — Prisma does not create indexes automatically for relation fields@@index
Source
https://prisma.io/docs/orm/prisma-schema
Process
- Read the instructions and examples in this document.
- Apply the patterns to your implementation, adapting to your specific context.
- Verify your implementation against the details and edge cases listed above.
Harness Integration
- Type: knowledge — this skill is a reference document, not a procedural workflow.
- No tools or state — consumed as context by other skills and agents.
Success Criteria
- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.