Database Seeding
Test and initial data generation with Prisma including basic seeds, Faker-based realistic data, environment-specific seeds, and idempotent seeding patterns.
What's Included#
- Basic seed script with admin user and category creation using upsert
- Faker-based seeding for realistic users, posts, and comments
- Environment-specific seed configurations (development, staging, production)
- Seed with deeply nested relations (teams, members, projects, tasks)
- Idempotent seeding using upsert and createMany with skipDuplicates
- Seed from JSON/CSV file data
- Test setup integration with beforeAll/afterAll hooks
- Package.json seed command configuration
Usage#
Via CLI#
Loading code block...
Via AI Assistant#
Ask your AI assistant:
- "Use the database seeding pattern from Bootspring"
- "Apply the Bootspring seeding pattern to my project"
Key Considerations#
- Make seeds idempotent using upsert or skipDuplicates so they can be run repeatedly
- Use different seed data for different environments (minimal for production, full for development)
- Always hash passwords securely in seeds; never store plaintext passwords
- Clear existing data before seeding in development to avoid duplicates
- Document test account credentials clearly so developers can find them easily
Related Patterns#
- Prisma - Prisma setup and basics
- Migrations - Migration strategies
- Transactions - Transaction handling