intermediate

Schema

Define models, relations, indexes, referential actions, generated types, and provider-specific constraints.

The Prisma schema (`schema.prisma`) defines models, fields, relations, indexes, datasource, and generator output. It drives generated TypeScript types and migration input.

					model Order {
  id         String   @id @default(cuid())
  customerId String
  customer   Customer @relation(fields: [customerId], references: [id])
  status     String   @default("pending")
  @@index([customerId, status])
}
				

On interviews: relation fields versus scalar foreign keys, referential actions (`onDelete`), indexes, enums, optionality, and provider-specific differences.

Common pitfalls: generated type safety mistaken for correct indexes or zero-downtime migrations; implicit many-to-many when the join needs attributes.

The trade-off is schema-as-contract convenience versus database operational reality.

Checklist:

  • Model relations explicitly.
  • Define indexes for access paths.
  • Review provider-specific behavior.
  • Treat schema changes as deploy events.