Overview
The seeding process populates your database with initial data required for development and testing. KAIU’s seed script is located atprisma/seed.ts.
Running the Seed Script
package.json:
What Gets Seeded
The seed script populates two main areas:- Initial Products - Sample product catalog
- Admin Users - System administrators from environment variables
Seed Script Breakdown
Imports and Setup
Product Seeding
Two initial products are created:1. Aceite Esencial de Lavanda
2. Kit Sueño Profundo
Admin User Seeding
Admin users are loaded from environment variables:Configuration
Setting Up Admin Users
In your.env or .env.local:
Database Connection
EnsureDATABASE_URL is set in prisma/.env:
Custom Seeding
Adding More Products
Editprisma/seed.ts and add to the INITIAL_PRODUCTS array:
Seeding Other Models
Add custom seeding logic to themain() function:
Seeding Workflow
Seed Output
Expected console output:Production Considerations
Don’t Seed Production
The seed script is for development and staging only. Production data should come from:- Admin panel product management
- Data imports
- Manual database operations
Sensitive Data
Never commit sensitive data toseed.ts. Always use environment variables:
Testing with Seeds
Use seeded data in tests:Troubleshooting
”Invalid Admin JSON env”
Check your environment variable format:Duplicate Key Errors
If you see constraint violations, the data already exists. The seed script usesupsert to prevent this, but manual database changes might cause conflicts.
Connection Errors
Ensure PostgreSQL is running andDATABASE_URL is correct:
Next Steps
- Learn about Database Migrations
- Review Prisma Schema
- Explore Testing Guide