Skip to main content

Prisma Schema Design & Migration Strategy

Design a Prisma schema with 1:1, 1:N, and M:N relations, composite indexes, enums, and a safe production migration strategy for your chosen database.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt asks the AI to design a complete Prisma schema for a [app_type] built around your [entities], then plan how to evolve it safely in production. It produces model definitions with fields, types, and constraints; 1:1, 1:N, and M:N relations with explicit join tables where needed; composite indexes tuned for your [query_patterns]; enums for [enum_fields]; a soft-delete pattern; audit-trail fields with middleware; full-text search config; multi-tenant isolation via [tenant_strategy]; a seed script sized to [seed_count]; and a zero-downtime plan for a [risky_migration].

The structure works because the schema is the most expensive part of a SaaS to get wrong, and this prompt forces the decisions that are painful to reverse — relations, indexes, and tenancy — to be made up front. Tying indexes to your real [query_patterns] keeps them purposeful rather than guessed, and asking for a zero-downtime path for [risky_migration] means a risky column change is rehearsed before it touches live traffic instead of discovered during an outage. The soft-delete and audit-trail requirements also bake consistency into every model, so you are not retrofitting deletedAt columns and createdBy tracking later once data has accumulated.

When to use it

  • You are starting a new SaaS and want the data model reasoned through before writing application code.
  • You need multi-tenant isolation and want it baked into the schema rather than bolted on later.
  • Your queries are slow and you suspect missing or wrong composite indexes for your [query_patterns].
  • You are about to run a risky migration (renaming or dropping a column in use) and want a safe sequence.
  • You want consistent soft-delete and audit-trail behavior across every model.
  • You need realistic seed data to develop and demo against.

Example output

Expect a complete schema.prisma file with your models, relations, enums, and indexes, plus a seed script and the migration commands to run. The zero-downtime section reads as an ordered, multi-step plan (expand, backfill, switch reads, contract) for the [risky_migration], with the reasoning for each step rather than a single destructive migration. You also get the middleware code that populates audit fields and a soft-delete query filter, so the patterns are wired in rather than left as a description.

Pro tips

  • List [entities] in dependency order and name the relationships you expect, so the AI maps join tables and cascades correctly.
  • Make [query_patterns] specific (for example, tasks by project and status) — that is what drives the composite-index choices.
  • Choose [tenant_strategy] deliberately; row-level isolation with an organizationId differs a lot from a database-per-tenant approach in the generated code.
  • Set [enum_fields] only for values that are genuinely closed sets, since enums are harder to change later than a lookup table.
  • Describe [risky_migration] precisely so the zero-downtime plan addresses your actual change, not a generic example.
  • Keep [seed_count] modest while iterating; large seeds slow the feedback loop during schema development.

Frequently Asked Questions

Which databases does this work with?
Any database Prisma supports, since the schema is expressed in Prisma's own syntax. You can target PostgreSQL, MySQL, SQLite, or others, though some features like full-text search and row-level security depend on the specific database you choose.
How does it handle multi-tenancy?
Through the `[tenant_strategy]` variable, which defaults to row-level isolation using an `organizationId`. The prompt builds tenant scoping into the models so each tenant only sees its own rows, but you should still enforce that scope in your application or database policies.
What does the zero-downtime migration plan cover?
It produces an ordered plan for the `[risky_migration]` you describe, typically an expand-and-contract sequence that adds new structures, backfills data, switches reads, then removes old columns. This avoids a single destructive migration that could break running production queries.
Does it include audit and soft-delete behavior?
Yes. The prompt adds a `deletedAt` soft-delete pattern and `createdBy`/`updatedBy` audit fields with middleware to populate them. This gives you consistent history and recoverable deletes across every model rather than per-model special cases.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Node.js & TypeScript Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support