db-seed-generator
Skill3 starsChanged 9 months agoMITView on GitHub
Generate realistic database seed data from a Prisma schema. Use when asked to generate seed data, create test data, populate the database, seed the DB, or create fixtures.
In this repository15 other files it gives its agents.
- ai-integration-generatorSkill
- api-docs-generatorSkill
- auth-scaffoldSkill
- code-reviewerSkill
- env-config-validatorSkill
- error-boundary-generatorSkill
- git-commit-composerSkill
- nextjs-middleware-generatorSkill
- nextjs-route-generatorSkill
- prisma-migration-reviewerSkill
- prisma-query-optimizerSkill
- react-component-generatorSkill
- test-generatorSkill
- typescript-refactorerSkill
- zod-schema-generatorSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 5 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Before generating any output, read config/defaults.md and adapt all patterns, imports, and code examples to the user's configured stack.
- Very specific: line 12
Read schema.prisma and extract all models, fields, types, constraints, relations, and enums.
- Distinctive: line 28
If circular dependencies exist, use a two-pass approach: create records with required fields first, then update with optional relation …
- Very specific: line 58
@unique: Ensure every value is unique. - Distinctive: line 62
Enums: Only use values defined in the enum.
- Distinctive: line 67
One-to-many: Create the "one" side first, reference its ID on the "many" side.
- Distinctive: line 69
Self-referencing: Create root records first (no parent), then children pointing to them.
- Distinctive: line 70
Required relations: Always satisfy — never leave a required FK null.
- Very specific: line 121
When the user specifies a count (e.g., "seed 50 users"), generate that many records.
- Very specific: line 125
Use upsert on a unique field to make the seed idempotent — safe to run multiple times.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DB Seed Generator
Before generating any output, read config/defaults.md and adapt all patterns, imports, and code examples to the user's configured stack.
Process
- Read
schema.prismaand extract all models, fields, types, constraints, relations, and enums. - Determine dependency order: models with no required relations first, then models that depend on them.
- Generate a
prisma/seed.tsfile with realistic fake data that respects all constraints. - Output a ready-to-run seed file.
Dependency Ordering
Build a directed graph of model dependencies from @relation fields. Topologically sort so parent records are created before children.
User (no deps) → create first
Organization (no deps) → create first
Post (depends on User) → create second
Comment (depends on User, Post) → create thirdIf circular dependencies exist, use a two-pass approach: create records with required fields first, then update with optional relation fields.
Data Generation Rules
Field Name Conventions
Generate realistic values based on field names:
| Pattern | Generated value |
firstName | "Elena", "Marcus", "Priya" |
lastName | "Rodriguez", "Chen", "Okafor" |
name (on User) | "Elena Rodriguez" |
email | "elena.rodriguez@example.com" |
phone | "555-0101", "555-0102" |
avatarUrl, imageUrl | "https://example.com/avatars/1.jpg" |
url, website | "https://example.com" |
title (on Post/Article) | Realistic short sentences |
content, body, description | 1-3 realistic sentences |
slug | Derived from title: "realistic-short-sentence" |
price, amount | Realistic numbers like 29.99, 149.00 |
quantity, count | Small integers: 1-100 |
createdAt, updatedAt | Dates spread over the last 90 days |
publishedAt | Either null or a date after createdAt |
isActive, isPublished | Mix of true/false |
role (enum) | Distribute across valid enum values |
password | Pre-hashed placeholder: "$2b$10$..." — never plaintext |
Constraints
@unique: Ensure every value is unique. Use index suffixes:"user1@example.com","user2@example.com".@id @default(cuid()): Omit from create calls — let the database generate them.@default(now()): Omit or set explicit dates for predictable ordering.@default(value): Omit to use the default, or set explicitly for variety.- Enums: Only use values defined in the enum.
Int,Float: Respect@db.SmallInt,@db.Decimal(10,2)etc.
Relations
- One-to-many: Create the "one" side first, reference its ID on the "many" side.
- Many-to-many (implicit): Use
connectsyntax after both sides exist. - Self-referencing: Create root records first (no parent), then children pointing to them.
- Required relations: Always satisfy — never leave a required FK null.
- Optional relations: Mix of connected and null.
Output Template
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
async function main() {
// Clear existing data (reverse dependency order)
await prisma.comment.deleteMany();
await prisma.post.deleteMany();
await prisma.user.deleteMany();
// Seed in dependency order
const users = await Promise.all([
prisma.user.upsert({
where: { email: "elena.rodriguez@example.com" },
update: {},
create: {
email: "elena.rodriguez@example.com",
name: "Elena Rodriguez",
// ... fields
},
}),
// ... more users
]);
// Use createMany for bulk inserts where relations allow
await prisma.post.createMany({
data: [
{ title: "...", authorId: users[0].id },
// ...
],
});
console.log("Seeded: X users, Y posts, Z comments");
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(() => prisma.$disconnect());Scale Parameter
When the user specifies a count (e.g., "seed 50 users"), generate that many records. Default to 5-10 records per model. Use createMany for bulk inserts where possible. Wrap large seeds in a prisma.$transaction().
Upsert Pattern
Use upsert on a unique field to make the seed idempotent — safe to run multiple times.
Reference
See references/seed-patterns.md for dependency ordering details, realistic data patterns, and performance tips.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

