Database Seeding
The seed script creates initial data required for the app to function: plans, entitlements, and an admin user.
What This System Does
The seeding system:
- Creates default entitlements (features) that plans provide
- Creates subscription plans (Free and Pro)
- Links entitlements to plans
- Creates an admin user for development testing
Why It Exists
The app needs initial data to function: plans for subscriptions, entitlements for feature gating, and a test user. The seed script ensures this data exists consistently across all environments.
When You Need to Care About It
You'll interact with seeding when:
- Setting up a new development environment
- Adding new entitlements or plans
- Resetting your database
- Preparing for production deployment
What Gets Created
Entitlements (Features)
| Name | Display Name | Description |
|---|---|---|
| basic_access | Basic Access | Access to basic features and dashboard |
| pro_features | Pro Features | Access to advanced features and tools |
| api_access | API Access | Access to REST API endpoints |
| priority_support | Priority Support | Priority email support and faster response times |
Plans
| Name | Display Name | Price | Entitlements |
|---|---|---|---|
| free | Free Plan | $0/month | basic_access |
| pro | Pro Plan | $29/month | All entitlements |
Admin User
- Email:
admin@example.com - Role:
admin - Subscription: Pro Plan (active)
This user is for development testing. Remove or change in production.
Running the Seed
First Time Setup
pnpm db:setupThis runs:
prisma generate- Generates Prisma clientprisma db push- Creates tables in databasepnpm db:seed- Seeds initial data
Re-seeding
To run seed again (safe to run multiple times):
pnpm db:seedThe seed uses upsert operations, so running it multiple times won't create duplicates.
Seed File Location
/prisma/seed.tsThis file is configured in package.json:
{
"prisma": {
"seed": "tsx prisma/seed.ts"
}
}Adding New Entitlements
1. Add to entitlements array
In /prisma/seed.ts:
prisma.entitlement.upsert({
where: { name: "your_feature" },
update: {},
create: {
name: "your_feature",
displayName: "Your Feature",
description: "What this feature provides",
},
}),2. Link to a plan
// Add to Pro plan
await prisma.planEntitlement.upsert({
where: {
planId_entitlementId: {
planId: proPlan.id,
entitlementId: entitlements.find((e) => e.name === "your_feature")!.id,
},
},
update: {},
create: {
planId: proPlan.id,
entitlementId: entitlements.find((e) => e.name === "your_feature")!.id,
},
});3. Run the seed
pnpm db:seed4. Update PLAN_REQUIREMENTS
In /components/UpgradePrompt.tsx:
const PLAN_REQUIREMENTS = {
// ... existing
your_feature: { name: "Pro Plan", planName: "pro" },
};Adding New Plans
1. Create the plan
In /prisma/seed.ts:
const enterprisePlan = await prisma.plan.upsert({
where: { name: "enterprise" },
update: {},
create: {
name: "enterprise",
displayName: "Enterprise Plan",
description: "For large teams",
price: 9900, // $99.00 (in cents)
interval: "month",
isActive: true,
stripePriceId: "price_enterprise_monthly", // Placeholder for Stripe
razorpayPlanId: "plan_enterprise_monthly", // Placeholder for Razorpay
},
});2. Link entitlements to the new plan
3. Create the price/plan in your payment provider dashboard
4. Update the payment provider ID
# For Stripe
node scripts/update-stripe-price.js enterprise price_xxxxxxxxxxxxx
# For Razorpay
node scripts/update-razorpay-plan.js enterprise plan_xxxxxxxxxxxxx5. Update pricing page UI
In /app/pricing/page.tsx.
Updating Payment Provider Plan IDs
After creating products/plans in your payment provider dashboard:
Stripe
# Update Pro plan price
node scripts/update-stripe-price.js pro price_xxxxxxxxxxxxx
# Update Enterprise plan price
node scripts/update-stripe-price.js enterprise price_xxxxxxxxxxxxxRazorpay
# Update Pro plan
node scripts/update-razorpay-plan.js pro plan_xxxxxxxxxxxxx
# Update Enterprise plan
node scripts/update-razorpay-plan.js enterprise plan_xxxxxxxxxxxxxThe scripts are located at:
/scripts/update-stripe-price.js/scripts/update-razorpay-plan.js
Seed Order
The seed script runs in this order:
- Create Entitlements - Features that plans provide
- Create Plans - Free and Pro plans
- Link Entitlements to Plans - Which plan has which features
- Create Admin User - Test user with Pro plan
This order matters because plans reference entitlements, and subscriptions reference both users and plans.
Resetting the Database
To completely reset and re-seed:
# Drop all tables and recreate
npx prisma db push --force-reset
# Re-seed
pnpm db:seed⚠️ Warning: This deletes all data. Only use in development.
Production Seeding
For production:
- Run
prisma db pushto create tables - Run
pnpm db:seedto create plans and entitlements - Remove or update the admin user (don't leave
admin@example.com) - Update payment provider IDs with production values
# For Stripe
node scripts/update-stripe-price.js pro price_live_xxxxxxxxxxxxx
# For Razorpay
node scripts/update-razorpay-plan.js pro plan_live_xxxxxxxxxxxxxSee Deployment for complete production setup guide.
Verifying Seed Data
Use Prisma Studio to inspect seeded data:
pnpm db:studioThis opens a web UI to view all database tables.
Troubleshooting
"Plan not found" Error
The seed hasn't run. Execute:
pnpm db:seed"Payment Provider ID" Error
The plan has a placeholder ID. Update it with your actual payment provider ID:
# For Stripe
node scripts/update-stripe-price.js pro price_xxxxxxxxxxxxx
# For Razorpay
node scripts/update-razorpay-plan.js pro plan_xxxxxxxxxxxxxDuplicate Key Error
This shouldn't happen with upsert. If it does, reset the database:
npx prisma db push --force-reset
pnpm db:seedSeed Fails to Run
Check that tsx is installed and package.json has the prisma seed config:
{
"prisma": {
"seed": "tsx prisma/seed.ts"
}
}Important Files
/prisma/seed.tsSeed script with all initial data
🏗️ EDITABLE
/scripts/update-stripe-price.jsScript to update Stripe price IDs
🏗️ EDITABLE
/scripts/update-razorpay-plan.jsScript to update Razorpay plan IDs
🏗️ EDITABLE
Related Sections
- Database - Understanding the schema
- Payments - Payment provider setup
- Entitlements - Understanding entitlements
- Deployment - Production setup