skills/prisma-cli-db-seed/SKILL.md
prisma db seed. Reference when using this Prisma feature.
npx skillsauth add prisma/cursor-plugin prisma-cli-db-seedInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Runs your database seed script to populate data.
prisma db seed [options]
| Option | Description |
|--------|-------------|
| --config | Custom path to your Prisma config file |
| -- | Pass custom arguments to seed script |
Configure seed script in prisma.config.ts:
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config'
export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: {
path: 'prisma/migrations',
seed: 'tsx prisma/seed.ts', // Your seed command
},
datasource: {
url: env('DATABASE_URL'),
},
})
// TypeScript with tsx
seed: 'tsx prisma/seed.ts'
// TypeScript with ts-node
seed: 'ts-node prisma/seed.ts'
// JavaScript
seed: 'node prisma/seed.js'
// prisma/seed.ts
import { PrismaClient } from '../generated/client'
const prisma = new PrismaClient()
async function main() {
// Create users
const alice = await prisma.user.upsert({
where: { email: '[email protected]' },
update: {},
create: {
email: '[email protected]',
name: 'Alice',
posts: {
create: {
title: 'Hello World',
published: true,
},
},
},
})
const bob = await prisma.user.upsert({
where: { email: '[email protected]' },
update: {},
create: {
email: '[email protected]',
name: 'Bob',
},
})
console.log({ alice, bob })
}
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
prisma db seed
prisma db seed -- --environment development
Arguments after -- are passed to your seed script.
In Prisma 7, seeding is NOT automatic after migrations:
# v7 workflow
prisma migrate dev --name init
prisma generate
prisma db seed # Must run explicitly
Previously (v6), migrate dev and migrate reset auto-ran seeds.
Use upsert to make seeds re-runnable:
// Good: Can run multiple times
await prisma.user.upsert({
where: { email: '[email protected]' },
update: {}, // Don't change existing
create: { email: '[email protected]', name: 'Alice' },
})
// Bad: Fails on second run
await prisma.user.create({
data: { email: '[email protected]', name: 'Alice' },
})
prisma migrate reset --force
prisma db seed
// prisma/seed.ts
const count = await prisma.user.count()
if (count === 0) {
// Only seed if empty
await seedUsers()
}
// prisma/seed.ts
const env = process.env.NODE_ENV || 'development'
if (env === 'development') {
await seedDevData()
} else if (env === 'test') {
await seedTestData()
}
upsert for idempotent seedsdatabases
Schema Changes. Reference when using this Prisma feature.
tools
Removed Features. Reference when using this Prisma feature.
tools
Prisma Config. Reference when using this Prisma feature.
tools
ESM Support. Reference when using this Prisma feature.