Generate Prisma Schema for SQL or MongoDB Databases
Use this AI prompt to generate Prisma schema files defining models, relationships, and enums, optimized for SQL or MongoDB connections.
🧠 What This Prompt Does
This prompt generates a Prisma schema with relational models, enums, and fields for database-first or schema-first setups.
It’s useful for teams using Prisma ORM in Node.js backends.
💬 The Prompt
You are a Prisma ORM expert.
Generate a Prisma schema file with:
- Models for the given entities
- One-to-many and many-to-many relations
- Enums where suitable
- Timestamps
Database context:
{{database_context}}
⚙️ Example Input
{ "database_context": "Postgres app with User, Post, and Comment models" }
🚀 Example Output (AI Generated)
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
name String
email String @unique
posts Post[]
createdAt DateTime @default(now())
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
user User @relation(fields: [userId], references: [id])
userId Int
comments Comment[]
createdAt DateTime @default(now())
}
model Comment {
id Int @id @default(autoincrement())
text String
post Post @relation(fields: [postId], references: [id])
postId Int
createdAt DateTime @default(now())
}
📘 When to Use This Prompt
- When setting up Prisma for a new backend.
- During data modeling phase for relational databases.
- When migrating from raw SQL schemas.
💡 Best Practices
- Use
@idand@defaultfor primary keys. - Always define
@relationfields explicitly. - Keep enum values uppercase for clarity.
- Use
@uniqueand@indexon query-heavy fields.
🏁 Summary
This prompt generates Prisma schema files that are structured, type-safe, and production-ready for relational or NoSQL databases.
Frequently Asked Questions
Does Prisma support MongoDB and SQL?
Yes, Prisma supports PostgreSQL, MySQL, SQLite, and MongoDB with slightly different syntax.
Can I define relations between models?
Yes, use `@relation` to define one-to-many or many-to-many connections.
Where do I define the provider?
Inside the datasource block, e.g., `provider = "postgresql"` or `"mongodb"`.
prismaschemadatabaseai-prompt
Advertisement
Advertisement