Schema
The schema.prisma mental model and the main constructs you will use every day.
Schema
The schema is the contract for the whole system. It drives code generation, runtime metadata, validation, and migration planning.
Supported top-level blocks
datasourcegeneratormodelenum
Minimal example:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "comon_orm"
output = "lib/generated/comon_orm_client.dart"
}
enum Role {
admin
member
}
model User {
id Int @id @default(autoincrement())
email String @unique
role Role
}What lives in schema and what does not
Use the schema for:
- data model structure
- keys, unique constraints, and indexes
- relation ownership and referential actions
- enum definitions
- logical-to-physical name mapping through
@mapand@@map - generator configuration such as output path and SQLite helper flavor
Do not expect the schema alone to replace rollout decisions. A destructive schema diff still needs human review at migration time.
Datasource and generator
Provider selection, URLs, output path, and Flutter SQLite helper mode.
Models and fields
Scalar types, defaults, ids, uniques, maps, indexes, and Dart type mapping.
Reference
Scalar types, attributes, generator options, and supported schema keywords.
Relations
One-to-one, one-to-many, self-relations, and compound relation references.
Enums
Define enum blocks, use them in models, and understand Dart and migration behavior.
Native types
See the supported PostgreSQL and SQLite @db.* subset and the matching Dart types.