Welcome to the Jose Madrid Salsa developer docs — explore features, APIs, and deployment guides.
Jose Madrid SalsaJMS Docs

Database Seeding

Seed the database with initial categories, products, users, and recipes

Database Seeding

The seed script at prisma/seed.ts populates the database with initial data for development and testing. It creates categories, products, users, and recipes.

Running the Seed

npx prisma db seed

Or directly:

npx tsx prisma/seed.ts

What Gets Seeded

1. Cleanup

The seed script first deletes all existing data in dependency order:

prisma/seed.ts
await prisma.orderItem.deleteMany()
await prisma.order.deleteMany()
await prisma.cartItem.deleteMany()
await prisma.wishlistItem.deleteMany()
await prisma.review.deleteMany()
await prisma.fundraiserProduct.deleteMany()
await prisma.fundraiser.deleteMany()
await prisma.product.deleteMany()
await prisma.category.deleteMany()
await prisma.address.deleteMany()
await prisma.wholesaleAccount.deleteMany()
await prisma.recipe.deleteMany()
await prisma.user.deleteMany()

Running the seed script deletes all existing data before inserting fresh records. Never run this against a production database.

2. Categories

Four salsa categories are created:

CategorySlugSort Order
Mild Salsamild-salsa1
Medium Salsamedium-salsa2
Hot Salsahot-salsa3
Gourmet & Fruit Salsagourmet-fruit-salsa4

3. Products

Products are created with Jose Madrid Salsa branding, including:

  • Name, slug, description
  • Heat level (MILD, MEDIUM, HOT, EXTRA_HOT)
  • Ingredients list
  • Pricing (price, compare-at price, cost price)
  • SKU and initial inventory
  • Category assignment

Example:

prisma/seed.ts
{
  name: 'Jose Madrid Original Mild',
  slug: 'jose-madrid-original-mild',
  heatLevel: HeatLevel.MILD,
  ingredients: ['Tomatoes', 'Onions', 'Bell Peppers', 'Garlic', 'Vinegar', 'Salt', 'Spices'],
  price: 8.99,
  sku: 'JMS-MILD-001',
  inventory: 100,
}

4. Users

Test users are created with bcrypt-hashed passwords:

  • Admin user
  • Customer users
  • Wholesale account user
  • Fundraiser account user

5. Recipes

Recipe data is imported from lib/data/recipes and seeded with:

  • Title, slug, description
  • Category, difficulty, prep/cook time
  • Ingredients and instructions
  • Featured image

6. Nutritional Info

The seed calls seedNutritionAndIngredients() from scripts/seed-nutrition-ingredients.ts to populate nutritional data for products.

Seed Files

FilePurpose
prisma/seed.tsMain seed script
prisma/seed.permissions.tsPermissions and role-permission mappings
prisma/seeds/retail-locations.tsRetail location data
prisma/seed.backup.tsBackup of previous seed data

Prisma Seed Configuration

The seed command is configured in package.json:

package.json
{
  "prisma": {
    "seed": "tsx prisma/seed.ts"
  }
}

The seed script uses tsx to run TypeScript directly without a separate compilation step.

Permissions Seed

prisma/seed.permissions.ts sets up the RBAC permission system:

  • Creates Permission records (e.g., orders:read, products:write)
  • Creates RolePermission mappings for each UserRole

Run it separately:

npx tsx prisma/seed.permissions.ts

How is this guide?

Edit on GitHub

Last updated on

On this page