Lesson 8 of 20Database Seeding & Relations Optimization

Click to Play Lecture (1080p Full HD)

Instructor: DevAscent Lead Architect • 60m 00s

14:20 / 60:001080p

Prisma Relational Modeling & Index Strategy

In this lesson, we structure relational entities for high-scale performance in PostgreSQL. We avoid common N+1 query traps and design compound indexes on foreign keys (`userId`, `courseId`).

Key Engineering Rules

  • Always use explicit relations in `schema.prisma` with `@relation(fields: [...], references: [...])`.
  • Add `@@index([userId, courseId])` to speed up student progress checks to under 2ms.
  • Wrap multi-step database writes in `prisma.$transaction([...])` to guarantee ACID properties.