Skip to content
Back to skills

Database Model

ASecurity

Create Prisma schema models with relations and indexes. Use when designing database schemas, adding models, or defining entity relationships.

  • 666 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added February 8, 2026
databasesgosqldatabase

Works with

  • cli

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill database-model --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Database Model?

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

Security grade badge for Database Model
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-database-model/badge)](https://www.skillsdirectory.com/skills/majiayu000-database-model)

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: database-model
description: Create Prisma schema models with relations and indexes. Use when designing database schemas, adding models, or defining entity relationships.
---

## ⚠️ CRITICAL - DO NOT MODIFY

```prisma
// prisma/schema.prisma - NEVER change these blocks
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
```

Import: `import { prisma } from '@/lib/prisma'` (already exists)

## Model Conventions

```prisma
model Product {
  id        String   @id @default(uuid())
  name      String
  price     Float    // Use Float for UI (returns number directly)
  isActive  Boolean  @default(true)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  category   Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
  categoryId String

  @@index([categoryId])
  @@index([name])
}
```

**Rules:**
- Model names: PascalCase
- Field names: camelCase
- IDs: `@id @default(uuid())`
- Always: `createdAt`, `updatedAt`
- Always: `@@index` on foreign keys

## Number Types

| Type | Returns | Use Case |
|------|---------|----------|
| `Int` | number | Counts, whole numbers |
| `Float` | number | Prices (recommended) |
| `Decimal` | Prisma.Decimal | Financial (needs conversion) |

## Relations

### One-to-Many
```prisma
model Category {
  id       String    @id @default(uuid())
  name     String    @unique
  products Product[]
}

model Product {
  id         String   @id @default(uuid())
  category   Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
  categoryId String
  @@index([categoryId])
}
```

### One-to-One
```prisma
model User {
  id      String   @id @default(uuid())
  profile Profile?
}

model Profile {
  id     String @id @default(uuid())
  user   User   @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId String @unique  // @unique = one-to-one
}
```

### Many-to-Many
```prisma
model Post {
  id   String @id @default(uuid())
  tags Tag[]  // Prisma handles junction table
}

model Tag {
  id    String @id @default(uuid())
  name  String @unique
  posts Post[]
}
```

## NextAuth Models

User, Account, Session already exist in boilerplate. Just add relations:
```prisma
model User {
  // ... existing fields
  posts Post[]  // Add your relations
}
```

## After Schema Changes

DO NOT run db push manually. Runs automatically in validation phase.

## NEVER
- Modify datasource/generator blocks
- Recreate lib/prisma.ts
- Recreate User/Account/Session
- Forget @@index on foreign keys
- Skip onDelete: Cascade on children
- Run db push during implementation

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.