Create Optimized Prisma Schema

backend
Prisma
architecture
strict_senior
Remix

Design production-ready Prisma schema with relations, indexes, and performance optimizations.

12/8/2025

Prompt

Create an optimized Prisma schema for [APPLICATION_NAME] with the following specifications:

Requirements

  • Application name: [APPLICATION_NAME]
  • Database type: [PostgreSQL/MySQL/SQLite/MongoDB]
  • Core entities: [ENTITY_1], [ENTITY_2], [ENTITY_3]
  • Relationships:
    • One-to-many: [PARENT] -> [CHILD]
    • One-to-one: [ENTITY_A] <-> [ENTITY_B]
    • Many-to-many: [ENTITY_X] <-> [ENTITY_Y]
  • ID strategy: [UUID/CUID/Auto-increment]
  • Timestamp tracking: [YES/NO]
  • Soft deletes: [YES/NO]
  • Enums needed: [ENUM_1], [ENUM_2]
  • Full-text search on: [FIELDS]
  • Composite unique constraints: [FIELD_COMBINATIONS]

Deliverables

Generate complete schema.prisma file with:

Generator and datasource configuration:

  • Prisma Client generator with output path
  • Datasource provider: [DATABASE_TYPE]
  • Database URL from environment variable
  • Preview features if needed (fullTextSearch, etc.)

Core models for each [ENTITY]:

  • Model definition with proper naming (PascalCase)
  • ID field with [ID_STRATEGY] (@id @default(cuid()))
  • All required fields with appropriate types
  • Optional fields marked with ?
  • createdAt/updatedAt timestamps if [TIMESTAMP_TRACKING]
  • deletedAt for soft deletes if needed

One-to-many relationships:

  • Foreign key field on child model
  • Relation field on both models
  • @relation with fields and references
  • onDelete behavior (Cascade/SetNull/Restrict)
  • Indexes on foreign keys for performance

One-to-one relationships:

  • @unique constraint on foreign key
  • Optional or required based on requirements
  • Bidirectional relation fields

Many-to-many relationships:

  • Implicit or explicit join table based on complexity
  • Relation fields on both models
  • Additional fields in explicit join tables if needed

Enums for [ENUMS]:

  • Enum definition with all values
  • Usage in model fields
  • @default values where appropriate

Performance indexes:

  • @@index on frequently queried fields
  • @@unique for unique constraints
  • Composite indexes with @@index([field1, field2])
  • Full-text indexes with @@fulltext([fields]) if [DATABASE_TYPE] supports

Constraints and validation:

  • @@unique for single or composite uniqueness
  • @default for default values
  • Proper data types (String, Int, Float, Boolean, DateTime, Json)
  • @db.VarChar() or other database-specific types if needed

Best practices implementation:

  • Consistent naming conventions
  • Proper cascade behaviors
  • Strategic index placement
  • Normalized data structure
  • Efficient query patterns support

Comments and documentation:

  • /// Model documentation
  • Field descriptions for complex fields
  • Relation explanation if complex

Output complete schema.prisma ready for prisma generate and prisma migrate.

Tags

prisma
database
orm
schema

Tested Models

gpt-4
claude-3-5-sonnet

Comments (0)

Sign in to leave a comment

Sign In