schema.prisma là single source of truth cho Prisma — ba sections: datasource, generator, models; @relation cho FK, @map cho tên column khác, prisma migrate dev tạo SQL migration reviewable. schema.prisma là single source of truth với ba sections: datasource (kết nối DB), generator (config Prisma Client), và models.
- Relations syntax: @relation('PostToUser', fields: [authorId], references: [id]) cho foreign key; implicit M2M relations dùng junction table tự động.
- Enums được định nghĩa trực tiếp và map đến DB enums hoặc strings. @map/@db directives quan trọng: @map('user_name') đổi field name trong DB trong khi giữ camelCase trong code; @db.VarChar(255) chỉ định DB-specific type.
- Multi-schema support (preview): datasource db { schemas: ['public', 'auth'] } cho multi-tenant apps. prisma format tự động format và sort fields.
prisma migrate devtạo SQL migration files có thể review và edit trước khi apply — quan trọng khi cần migration phức tạp như data migration.