Generate Seed Script for Prisma Database
Use this AI prompt to generate a Prisma database seed script to populate sample data across multiple models using async operations.
🧠 What This Prompt Does
This prompt helps you generate a database seed script for Prisma ORM, useful for testing and local development environments.
💬 The Prompt
You are a Prisma developer.
Generate a seed script that:
- Uses async/await
- Creates sample records for each model
- Handles relational data
- Uses PrismaClient for connection
🚀 Example Output (AI Generated)
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
const user = await prisma.user.create({
data: {
name: 'John Doe',
email: 'john@example.com',
posts: {
create: [{ title: 'Hello World', content: 'My first blog post!' }],
},
},
});
console.log('Seeded user:', user);
}
main()
.catch((e) => console.error(e))
.finally(async () => await prisma.$disconnect());
📘 When to Use This Prompt
- During local development or testing.
- When needing sample data for demo purposes.
- After initial migrations to verify schema.
💡 Best Practices
- Always truncate old data before reseeding.
- Use faker.js for realistic data generation.
- Never run seeds on production DBs.
- Include seed commands in CI setup for local automation.
🏁 Summary
This prompt generates ready-to-run Prisma seed scripts that populate your database with realistic sample data efficiently.
Frequently Asked Questions
Where should the Prisma seed file be located?
In the `prisma/seed.ts` or `prisma/seed.js` file, configured via `package.json` under scripts.
Can I seed relational data?
Yes, you can use nested `create` operations to insert relational data in one go.
Is seeding safe for production?
No. Use seeding only for local or staging environments.
prismaseeddatabaseai-prompt
Advertisement
Related Prompts
Advertisement