Prisma Schema Generator
Describe each model as one line of fields and get a schema.prisma with datasource, generator, relation fields and the matching foreign key columns.
Use the tool
Why this tool exists
Prisma relations take a surprising amount of typing: the relation field, the scalar foreign key, the @relation arguments and the list on the other side all have to agree. Forgetting one produces a validation error that is clear but tedious to fix.
With this tool you write something like User: id:int pk, email:string unique, posts:Post[] and it adds the author relation, authorId and references on the Post side. You pick the provider, and for MongoDB it uses ObjectId mapping. It supports one relation per pair of models, so named relations need hand edits. Run prisma format and prisma validate on the result.
How to use it
- Write one model per line as Name: field:type modifiers, separated by commas.
- Choose the database provider, the env variable for the URL and whether to add snake_case @@map names.
- Copy the schema into schema.prisma and run prisma validate.
Frequently asked questions
What modifiers can I use?
pk, unique, now, updatedAt, default=value, map=name and cuid for string ids. A question mark after a type makes it optional, and square brackets make a list.
How are relations written?
Name another model as a type. A list such as posts:Post[] creates the foreign key on Post. A single such as author:User creates authorId on that model, and a list is added to User if missing.
Does it support composite keys or enums?
No. Only a single pk per model, scalar types and relations are generated. Add enums, composite ids and named relations by hand.
Which types can I use?
int, string, bool, float, datetime, json, bigint, decimal and bytes, in any letter case. Any other name must match one of your models.