Skip to content

commandDatabases

Seed Database

Writes a seed script with realistic, properly related sample data that is safe to run twice and refuses to run in production.

npx workspacetemplates add seed-database --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/seed-database.md14 lines · 1.2 KBFile
---
description: Writes a seed script with realistic, properly related sample data that is safe to run twice and refuses to run in production.
argument-hint: "[tables or feature to seed]"
---

Write a seed script for: $ARGUMENTS (tables, feature, or "all").

1. Read the schema, models and migrations. Map the tables, their foreign keys, unique keys, enums and required fields. Note the project's seed convention (prisma/seed.ts, db/seeds.rb, fixtures, a management command) and follow it.
2. Plan the insert order from parents to children. Use realistic values: plausible names, emails at example.com, dates over the last year, prices with sensible ranges. Add edge cases deliberately: a long name, a null optional field, an inactive user, a zero-total order.
3. Make it idempotent: upsert on a natural key or truncate only seed-owned rows, using a fixed random seed so data is the same every run.
4. Add a guard: abort if the database URL contains prod or a non-local host unless `ALLOW_SEED=1`.
5. Never use real customer data and never write secrets or real passwords. Hash a known dev password.

Print row counts per table and the command to run it. Do not run it until the user confirms which database it points to.

What it does

Empty tables make every screen look broken, and random strings make demos look fake. This command reads your schema and writes a seed script with believable names, valid foreign keys and a mix of normal and edge-case rows.

The script is idempotent, so running it again does not duplicate anything, and it stops itself when pointed at anything that looks like production.

Example

you › /seed-database shop: customers, products, orders

agent › Wrote prisma/seed.ts: 25 customers, 60 products in 6 categories, 140 orders with 1 to 5 items. Includes one refunded order and one customer with no orders.
Upserts by email and sku, seed fixed at 42, aborts on non-local URLs.
Run npx prisma db seed against localhost?

Questions

Can I run it twice?
Yes. Rows are upserted on stable keys, so a second run leaves the same data.
Could it touch my production database?
The script refuses to run when the connection string looks remote or production, unless you set an explicit override.
  • Add Index

    CommandDatabases

    Free
  • Explain Query

    CommandDatabases

    Free
  • Schema Diff Review

    CommandDatabases

    Free
  • Write Migration

    CommandDatabases

    Free