askill
prisma-cli-db-seed

prisma-cli-db-seedSafety 80Repository

prisma db seed. Reference when using this Prisma feature.

0 stars
1.2k downloads
Updated 2/9/2026

Package Files

Loading files...
SKILL.md

prisma db seed

Runs your database seed script to populate data.

Command

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

OptionDescription
--configCustom path to your Prisma config file
--Pass custom arguments to seed script

Configuration

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'),
  },
})

Common seed commands

// TypeScript with tsx
seed: 'tsx prisma/seed.ts'

// TypeScript with ts-node
seed: 'ts-node prisma/seed.ts'

// JavaScript
seed: 'node prisma/seed.js'

Seed Script Example

// 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: 'alice@prisma.io' },
    update: {},
    create: {
      email: 'alice@prisma.io',
      name: 'Alice',
      posts: {
        create: {
          title: 'Hello World',
          published: true,
        },
      },
    },
  })

  const bob = await prisma.user.upsert({
    where: { email: 'bob@prisma.io' },
    update: {},
    create: {
      email: 'bob@prisma.io',
      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

prisma db seed

With custom arguments

prisma db seed -- --environment development

Arguments after -- are passed to your seed script.

v7 Changes

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.

Idempotent Seeding

Use upsert to make seeds re-runnable:

// Good: Can run multiple times
await prisma.user.upsert({
  where: { email: 'alice@prisma.io' },
  update: {},  // Don't change existing
  create: { email: 'alice@prisma.io', name: 'Alice' },
})

// Bad: Fails on second run
await prisma.user.create({
  data: { email: 'alice@prisma.io', name: 'Alice' },
})

Common Patterns

Development reset

prisma migrate reset --force
prisma db seed

Conditional seeding

// prisma/seed.ts
const count = await prisma.user.count()
if (count === 0) {
  // Only seed if empty
  await seedUsers()
}

Environment-specific seeds

// prisma/seed.ts
const env = process.env.NODE_ENV || 'development'

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

Best Practices

  1. Use upsert for idempotent seeds
  2. Keep seeds focused and minimal
  3. Use realistic but fake data
  4. Document required seed data
  5. Version control your seed scripts

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

87/100Analyzed 2/22/2026

High-quality reference document for Prisma db seed command. Provides comprehensive coverage including command syntax, configuration in prisma.config.ts, seed script examples, v7 changes, idempotent patterns, and best practices. Well-structured with tables, code examples, and multiple usage scenarios. The skill is properly located in a skills folder with metadata (author, version) and tags for discoverability. While found in a repo, the content is general Prisma documentation, not internal-only."

80
90
85
88
92

Metadata

Licenseunknown
Version-
Updated2/9/2026
Publisherprisma

Tags

databasegithub-actionstesting