AI
50 AI Prompts for Prisma ORM and Database Design
Developer-tested AI prompts for Prisma schema design, database relations, migrations, typed queries, transactions, connection pooling, and Next.js integration. Build data layers faster with copy-paste prompts.
Why Prisma Developers Benefit from AI Prompts
Prisma combines a schema definition language, an auto-generated TypeScript client, and a migration system in one tool. The schema syntax is straightforward but the nuances of relations — especially many-to-many relations with explicit join tables, self-relations, and polymorphic patterns — are areas where AI prompts save significant time.
Prisma queries also require knowing the specific API for nested writes, relation filters, and transaction handling. These are not always intuitive and the documentation, while comprehensive, is dense. The prompts in this guide cover the patterns that developers look up most often — from schema design through to production optimization.
- Design Prisma schemas for complex domain models with correct relation types
- Generate typed Prisma queries for nested reads, filters, and aggregations
- Write migration scripts and understand the generated SQL before applying
- Handle transactions and batch operations correctly in Prisma
- Optimize slow queries with the right indexes and include strategies
Prisma Schema Design Prompts
A well-designed Prisma schema models the domain accurately, uses the right relation types, and includes indexes for the queries you will run most frequently. These prompts generate schemas for common application domains including SaaS multi-tenancy, e-commerce, content management, and social applications.
Always describe the entities, their fields with types, the relationships between them, and any uniqueness constraints. Also specify whether you need soft deletes (a deletedAt field) since that affects how Prisma queries need to be written throughout the application.
Act as a Prisma ORM expert.
Task:
Design a Prisma schema for a multi-tenant SaaS application.
Models needed:
- Tenant: id (cuid), name, slug (unique), plan (enum: FREE, PRO, ENTERPRISE), createdAt
- User: id (cuid), email (unique per tenant), name, role (enum: OWNER, ADMIN, MEMBER),
tenantId (FK), createdAt, lastSeenAt
- Project: id (cuid), name, description, status (ACTIVE, ARCHIVED, DELETED),
tenantId (FK), createdById (FK to User), createdAt, updatedAt
- Task: id (cuid), title, body, status (TODO, IN_PROGRESS, REVIEW, DONE),
projectId (FK), assignedToId (FK to User, optional), dueDate, createdAt, updatedAt
Requirements:
- Cascade delete: deleting a Tenant cascades to User, Project, Task
- Compound unique: email + tenantId (same email can exist in different tenants)
- Indexes: tenantId on all models, status on Task and Project, dueDate on Task
- Provider: postgresqlPrisma Relations and Complex Schema Prompts
Prisma supports one-to-one, one-to-many, and many-to-many relations. The many-to-many pattern is the most complex because Prisma supports both implicit join tables (for simple cases) and explicit join tables (when the relation itself carries data, such as a role on a membership). These prompts cover both patterns.
Self-relations — where a model has a relation to itself, such as a folder hierarchy or a comment thread with replies — require specific syntax in Prisma. The prompts in this section show the correct way to define self-referential relations with proper naming.
Act as a Prisma ORM expert.
Task:
Model these relationships in a Prisma schema:
1. User to Team: many-to-many via explicit TeamMember join model
TeamMember carries: role (OWNER, ADMIN, MEMBER), joinedAt
2. Post to Tag: many-to-many via implicit join table (no extra fields)
3. Comment self-relation: a Comment can have a parentId (replies)
Relation names: parent and replies
4. User to User: follower/following self-relation via explicit Follows model
Follows carries: createdAt
Relation names: followers, following
For each relationship:
- Show the complete model definitions
- Show an example Prisma Client query that traverses the relation
Provider: postgresqlPrisma Client Query Prompts
Prisma Client provides a fully-typed query API that covers everything from simple CRUD to nested writes, relation filters, and full-text search. These prompts generate typed queries for the patterns that developers reach for most: paginated lists with filters, nested creates, upserts, and aggregations.
When asking AI to generate Prisma queries, paste the relevant schema models into the prompt. This ensures the model uses the correct field names, relation names, and enum values from your actual schema rather than inventing them.
Act as a Prisma Client TypeScript expert.
Task:
Write the following Prisma queries against this schema:
[paste your schema here]
Queries needed:
1. Get all active projects for a tenant, with task counts and creator name,
paginated (skip/take), ordered by updatedAt descending
2. Create a new project and its first default task in a single nested write
3. Get task statistics for a project: total, by status, overdue count
4. Update a task status and the project updatedAt in a transaction
5. Find users who have not logged in for 30 days and have the MEMBER role
For each query: show the Prisma Client call with TypeScript types.Prisma Migrations Prompts
Prisma Migrate generates SQL migration files from schema changes. For most changes the generated SQL is straightforward, but some operations — renaming a column, changing a column type, and splitting a model into two — require a custom migration because Prisma cannot infer the intent from a diff alone.
These prompts help with migration planning, custom migration SQL generation, and understanding the impact of schema changes on existing data. Always review the generated SQL before running prisma migrate deploy in production.
Act as a Prisma Migrate expert.
Task:
I need to rename the fullName column to displayName in the User table
without losing existing data.
The default prisma migrate dev would DROP the old column and ADD a new one,
which would erase data. I need a safe migration instead.
Provide:
1. The updated Prisma schema showing the renamed field
2. The command to create an empty migration (--create-only)
3. The safe SQL to paste into the migration file (RENAME COLUMN)
4. The command to apply the migration
5. How to verify the rename worked without data loss
Provider: postgresqlPrisma with Next.js and API Routes Prompts
Prisma is one of the most popular ORMs for Next.js projects. In the App Router, the Prisma Client instance needs to be instantiated as a singleton to avoid exhausting the database connection pool in development (where Next.js hot reload creates new module instances repeatedly).
These prompts cover the singleton pattern, Next.js Server Actions with Prisma, Route Handlers that return paginated data, and the correct way to use Prisma with streaming Server Components. They also cover PrismaClientKnownRequestError handling for unique constraint violations.
Act as a Prisma and Next.js App Router expert.
Task:
Set up Prisma correctly for a Next.js App Router project.
Provide:
1. lib/prisma.ts: the singleton PrismaClient instance that avoids multiple
connections in Next.js development (hot reload issue)
2. A Server Action in app/actions/projects.ts:
- createProject(formData: FormData): creates a project, revalidates the /dashboard path
- Handle Prisma unique constraint error (P2002) and return a typed error object
3. A Route Handler in app/api/projects/route.ts:
- GET: paginated projects list with page and limit query params
- Returns: { data: Project[], total: number, page: number }
Use: Next.js 15 App Router, Prisma 6, TypeScript, Zod for input validationPrisma Performance and Connection Pooling Prompts
Prisma query performance depends on having the right indexes, using select to fetch only the fields you need, and avoiding the N+1 query problem with correct use of include and select. These prompts help identify slow queries and add the right Prisma schema indexes.
For serverless environments (AWS Lambda, Vercel Edge Functions), the standard Prisma Client opens a direct database connection that is incompatible with the ephemeral nature of serverless. Prisma Accelerate or a connection pooler like PgBouncer is required. These prompts cover the setup for both options.
Act as a Prisma performance expert.
Task:
Optimize this Prisma query that is taking over 2 seconds on 50k rows.
[paste slow query here]
Analyze and fix:
1. Is there an N+1 problem? Show the corrected query with include.
2. Are we fetching fields we do not need? Show a select-only version.
3. What indexes should be added to the schema for this query pattern?
Show the @@index() additions to the schema.
4. Should we use a raw SQL query for this specific case? Show the
prisma.$queryRaw version if it would be faster.
5. What does EXPLAIN ANALYZE show, and how to interpret it?
Schema: [paste relevant models here]FAQ
What is the best way to use AI for Prisma ORM?
Always paste the relevant Prisma schema models into the prompt. Without the actual field names, relation names, and enum values, AI invents names that do not match your schema. Include the schema, describe the query or operation you need, and specify which Prisma version you are using.
Can AI generate a Prisma schema from a description?
Yes. Describe each model, its fields with types, the relationships, and any uniqueness constraints or indexes. AI generates a complete schema.prisma file with correct relation syntax. Always review the generated SQL from prisma migrate dev --create-only before applying to a production database.
How do I prompt AI for Prisma many-to-many relations?
Specify whether the relation is implicit (no extra data on the join) or explicit (the join table carries additional fields). For explicit joins, describe the join model and its fields. The prompt in Section 3 shows both patterns side by side.
Can AI help me write complex Prisma queries?
Yes. Paste the schema models, describe what data you need to retrieve or write, and list any filters, ordering, or pagination requirements. For nested writes and transactions, describe the operation in plain language — AI translates it to the correct Prisma Client API.
How do I use AI to safely rename a Prisma column?
Ask AI for a safe column rename migration that avoids data loss. Prisma migrate dev would drop and recreate the column by default. AI provides the --create-only command and the RENAME COLUMN SQL to paste into the generated migration file. The prompt in Section 5 covers this exact pattern.
Can AI help with Prisma connection pooling for serverless?
Yes. Specify your serverless platform (AWS Lambda, Vercel) and ask for either the Prisma Accelerate setup or the PgBouncer configuration. Prisma Accelerate is the managed option; PgBouncer is self-hosted. Include your DATABASE_URL format in the prompt and AI provides the complete configuration.
What is the difference between Prisma ORM and raw SQL?
Prisma ORM provides a fully-typed query API that prevents SQL injection, auto-generates TypeScript types from your schema, and handles migrations. Raw SQL gives more control over query plans and is sometimes faster for complex aggregations. Prisma supports prisma.$queryRaw for cases where the typed API is not expressive enough.
How do I set up Prisma in a Next.js App Router project?
Create a lib/prisma.ts singleton that stores the PrismaClient instance on the Node.js global object in development. Without this, Next.js hot reload creates a new client on every file change, exhausting your database connection pool. The prompt in Section 6 provides the complete singleton pattern and a working Server Action example.
Related free tools
If you want to turn this topic into action, use one of ShortIQ's free tools for campaign planning, UTM structure, or QR distribution.
Continue Reading
Explore more guides on link shortener SaaS strategy, Bitly alternatives, and white label link management.
Free newsletter
Get new guides in your inbox
We publish practical guides on dev tooling, prompt engineering, marketing workflows, and deployment. No fluff — straight to the point.
No spam. Unsubscribe any time.
Was this article helpful?
Tell us if this guide solved the problem or what was still missing. We use this to improve the blog and only follow up if you explicitly allow it.