Labsco
prisma logo

prisma-cli-db-seed

✓ Official8

by prisma · part of prisma/cursor-plugin

prisma db seed. Reference when using this Prisma feature.

🔥🔥🔥✓ VerifiedFreeQuick setup
🧩 One of 7 skills in the prisma/cursor-plugin package — works on its own, and pairs well with its siblings.

prisma db seed. Reference when using this Prisma feature.

Inspect the full instructions your agent will receiveExpand

This is the exact playbook injected into your agent when the skill activates — shown here so you can audit it before installing. You don't need to read it to use the skill.

by prisma

prisma db seed. Reference when using this Prisma feature. npx skills add https://github.com/prisma/cursor-plugin --skill prisma-cli-db-seed Download ZIPGitHub8

prisma db seed

Runs your database seed script to populate data.

Command

Copy & paste — that's it
prisma db seed [options]

What It Does

  • Executes your configured seed script

  • Populates database with initial/test data

  • Runs independently (not auto-run by migrations in v7)

Options

Option Description --config Custom path to your Prisma config file -- Pass custom arguments to seed script

Seed Script Example

Copy & paste — that's it
// 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)
 })

Examples

Run seed

Copy & paste — that's it
prisma db seed

With custom arguments

Copy & paste — that's it
prisma db seed -- --environment development

Arguments after -- are passed to your seed script.

v7 Changes

In Prisma 7, seeding is NOT automatic after migrations:

Copy & paste — that's it
# 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.

Idempotent Seeding

Use upsert to make seeds re-runnable:

Copy & paste — that's it
// 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' },
})

Common Patterns

Development reset

Copy & paste — that's it
prisma migrate reset --force
prisma db seed

Conditional seeding

Copy & paste — that's it
// prisma/seed.ts
const count = await prisma.user.count()
if (count === 0) {
 // Only seed if empty
 await seedUsers()
}

Environment-specific seeds

Copy & paste — that's it
// prisma/seed.ts
const env = process.env.NODE_ENV || 'development'

if (env === 'development') {
 await seedDevData()
} else if (env === 'test') {
 await seedTestData()
}

Best Practices

  • Use upsert for idempotent seeds

  • Keep seeds focused and minimal

  • Use realistic but fake data

  • Document required seed data

  • Version control your seed scripts