Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Databasebeginner

Prisma Setup

Share

Set up Prisma ORM with schema and migrations

Works with OpenClaude

You are a backend developer setting up Prisma ORM in a Node.js project. The user wants to initialize Prisma, configure the database connection, define a schema, and run migrations.

What to check first

  • Run npm list prisma @prisma/client to verify Prisma packages aren't already installed
  • Check if a .env file exists in your project root with DATABASE_URL variable
  • Confirm your database (PostgreSQL, MySQL, SQLite, etc.) is running and accessible

Steps

  1. Install Prisma CLI and client library with npm install @prisma/client && npm install -D prisma
  2. Initialize Prisma with npx prisma init — this creates prisma/schema.prisma and .env file
  3. Set your DATABASE_URL in .env with the correct connection string for your database engine
  4. Update the datasource db block in prisma/schema.prisma to match your database type (postgresql, mysql, sqlite, etc.)
  5. Define your data models in prisma/schema.prisma using the model keyword with fields and types
  6. Run npx prisma migrate dev --name init to create your first migration and apply it to the database
  7. Generate the Prisma Client with npx prisma generate (automatically runs during migrate, but useful for manual updates)
  8. Test the connection by running npx prisma studio to open the web UI and verify schema structure

Code

// prisma/schema.prisma
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}
// src/index.js — Example usage after schema is set up
const { PrismaClient } = require('@prisma/client');

const prisma = new PrismaClient();

async function main() {
  // Create a new user
  const user = await prisma.user.create({
    data: {
      email: 'alice@example.com',
      name: 'Alice',
    },
  });

  // Create a post connected to the user
  const post = await prisma.post.create({
    data: {
      title: 'Hello World',
      content: 'This is my first post',
      published: true,
      authorId: user.id,
    },
  });

  // Query with relations
  const userWithPosts = await prisma.user.find

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryDatabase
Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
databaseprismaorm

Install command:

curl -o ~/.claude/skills/prisma-setup.md https://claude-skills-hub.vercel.app/skills/database/prisma-setup.md

Related Database Skills

Other Claude Code skills in the same category — free to download.

Want a Database skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.