seed

Populate Prisma databases with idempotent seed data using upsert.

Updated Apr 10, 2026
One-click install
npx skills add https://github.com/theslashdojo/dojo --skill seed-theslashdojo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: seed
Source: https://github.com/theslashdojo/dojo/tree/main/nodes/prisma/seed
Command: npx skills add https://github.com/theslashdojo/dojo --skill seed-theslashdojo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires prisma, @prisma/client, tsx, and includes scripts (resource) components.

What problem does it solve?

Database initialization and test fixture creation are repetitive and fragile tasks that often fail on duplicate keys or require manual scripts per project. Prisma seed scripts, when misconfigured, can be non-idempotent, hang the process, or be difficult to integrate into migration workflows. This Skill centralizes best practices for creating safe, repeatable seeds that developers can run reliably in development and test environments.

Core Features & Use Cases

  • Idempotent seeding with upsert: Use upsert and update: {} patterns so seeds can run multiple times without P2002 duplicate errors.
  • Seed runner configuration: Configure prisma.seed in package.json to point to a TypeScript or JavaScript runner such as tsx, ts-node, or node.
  • Bulk and generated data: Support bulk inserts with createMany and realistic data generation with @faker-js/faker for fixtures and load data.
  • Automation helper: Includes a script to generate a starter prisma/seed.ts and add the seed command to package.json for quick setup.
  • Use case: Initialize a fresh development database with admin users, lookup tables, and sample posts after applying migrations.

Quick Start

Create a prisma/seed.ts that uses upsert for your core models, add prisma.seed to package.json to run tsx prisma/seed.ts, and run npx prisma db seed to populate the database.

Frequently Asked Questions about seed

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make Prisma seed scripts idempotent and prevent duplicate key errors?

To make Prisma seed scripts idempotent, use the upsert operation with an update: {} pattern for your core models. This allows the seed script to run multiple times safely without triggering P2002 duplicate key errors in development and test environments.

How do I configure and run a Prisma seed script using TypeScript?

Configuring a Prisma seed script requires adding a prisma.seed entry in package.json pointing to a TypeScript runner like tsx. Once configured, you execute the script to populate the database by running the npx prisma db seed command.

What is the best way to generate bulk test fixtures with Prisma and Faker?

The best way to generate bulk test fixtures with Prisma is to combine the createMany method for bulk inserts with @faker-js/faker for realistic data generation. This approach efficiently populates lookup tables and creates load data for test environments.

Does Prisma db seed support repopulating data automatically after database migrations?

Yes, Prisma db seed supports repopulating data after applying migrations. By configuring idempotent seed scripts via prisma.seed in package.json, developers can reliably initialize fresh development databases with admin users and sample posts post-migration.

Why does my Prisma seed script hang or fail when run multiple times?

Prisma seed scripts hang or fail when run multiple times if they use standard create operations instead of idempotent upsert patterns. Implementing upsert with an empty update object prevents duplicate key conflicts and ensures the process exits cleanly.