Defining Your Prisma Schema
prisma/schema.prisma has three parts: a generator, a datasource, and one or more models.
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
Reading a model
- Each field has a name, a type (
Int,String,Boolean,DateTime, ...), and optional attributes. @idmarks the primary key.@default(autoincrement())lets PostgreSQL assign the next integer automatically, exactly likeSERIALin raw SQL.@uniqueadds a unique constraint, no two users can share an email.- A trailing
?(likeString?) makes a field optional, it maps to a nullable column.
Every model becomes a table, every field becomes a column, this is the same shape of data you already modeled in the SQL Fundamentals course, just described declaratively instead of with CREATE TABLE.