Prisma Schema Blueprint
Define application data models with fields, types, relationships, and validation rules in Prisma schema
| Feature | prisma-schema |
| Category | Data |
| Version | 1.0.0 |
| Tags | schema, models, orm, data-modeling, prisma |
| YAML Source | View on GitHub |
| JSON API | prisma-schema.json |
Actors
| ID | Name | Type | Description |
|---|---|---|---|
developer | Developer | human | |
schema_engine | Schema Engine | system |
Fields
| Name | Type | Required | Label | Description |
|---|---|---|---|---|
model_name | text | Yes | Model Name | |
field_name | text | Yes | Field Name | |
field_type | select | Yes | Field Type | |
is_required | boolean | Yes | Is Required | |
is_unique | boolean | Yes | Is Unique | |
default_value | text | No | Default Value | |
relation_type | select | No | Relation Type |
States
State field: model_status
Values:
| State | Initial | Terminal |
|---|---|---|
defined | Yes | |
generated | ||
migrated |
Rules
- naming: Models: PascalCase (User, BlogPost, OrderItem), Fields: camelCase (firstName, emailAddress, createdAt), Enums: UPPER_SNAKE_CASE values (ACTIVE, PENDING, ARCHIVED)
- validation: Required fields cannot be null in database, Unique constraints prevent duplicate values, Default values must match field type, Relations must reference existing models
- relationships: One-to-one: unique constraint on foreign key, One-to-many: implicit foreign key in child model, Many-to-many: automatic join table created, Cascade delete propagates to related records
Outcomes
Model_defined (Priority: 1)
Given:
- Schema block contains valid model definition
- All fields have supported types
Then:
- Model definition stored in schema
- model.defined event emitted
Result: Model definition stored and validated
Schema_validated (Priority: 1)
Given:
- All models syntactically valid
- All relations reference existing models
Then:
- schema.validated event emitted
Result: Schema ready for client generation
Invalid_type_error (Priority: 10) — Error: INVALID_FIELD_TYPE
Given:
- Field uses unsupported type
Result: Validation error: type not supported
Errors
| Code | Status | Message | Retry |
|---|---|---|---|
INVALID_FIELD_TYPE | 400 | Field type ‘{type}’ is not supported | No |
INVALID_RELATION | 400 | Relation references non-existent model | No |
SYNTAX_ERROR | 400 | Schema syntax error at line {line}: {error} | No |
Events
| Event | Description | Payload |
|---|---|---|
model.defined | Model definition created | name, field_count, relation_count |
schema.validated | Schema passed validation | model_count, field_count, validation_time_ms |
Related Blueprints
| Feature | Relationship | Reason |
|---|---|---|
| prisma-migrations | recommended | Schema must be migrated to create database |
| prisma-crud | recommended | Models are queried via CRUD operations |
AGI Readiness
Goals
Reliable Prisma Schema
Define application data models with fields, types, relationships, and validation rules in Prisma schema
Success Metrics:
| Metric | Target | Measurement |
|---|---|---|
| data_accuracy | 100% | Records matching source of truth |
| duplicate_rate | 0% | Duplicate records detected post-creation |
Constraints:
- performance (non-negotiable): Data consistency must be maintained across concurrent operations
Autonomy
Level: supervised
Human Checkpoints:
- before transitioning to a terminal state
Escalation Triggers:
error_rate > 5
Tradeoffs
| Prefer | Over | Reason |
|---|---|---|
| data_integrity | performance | data consistency must be maintained across all operations |
Safety
| Action | Permission | Cooldown | Max Auto |
|---|---|---|---|
| model_defined | autonomous | - | - |
| schema_validated | autonomous | - | - |
| invalid_type_error | autonomous | - | - |