Prisma generator to create an ER Diagram every time you generate your prisma client.
Like this tool? @Skn0tt started this effort with his web app ER diagram generator
npm i -D prisma-erd-generator @mermaid-js/mermaid-cli
# or
yarn add -D prisma-erd-generator @mermaid-js/mermaid-cli
Add to your schema.prisma
generator erd {
provider = "prisma-erd-generator"
}
Run the generator
npx prisma generate
- Prisma >= 4 use 1.x.x
- Prisma <4 use 0.11.x
Additional configuration
Change output type and location
Usage
generator erd {
provider = "prisma-erd-generator"
output = "../ERD.svg"
}
Extensions
- svg (default:
./prisma/ERD.svg
) - png
- md
Theme selection
Usage
generator erd {
provider = "prisma-erd-generator"
theme = "forest"
}
Options
- default (default)
- forest
- dark
- neutral
You won't always need to generate a new ER diagram. To disabled running this generator just add an environment variable to the environment running prisma generate
.
DISABLE_ERD=true
If you have issues with generating or outputting an ERD as expected, you may benefit from seeing output of the steps to making your ERD. Enable debugging by either adding the following environment variable
ERD_DEBUG=true
or adding in the debug configuration key set to true
generator erd {
provider = "prisma-erd-generator"
erdDebug = true
}
and re-running prisma generate
. You should see a directory and files created labeling the steps to create an ER diagram under prisma/debug
.
Please use these files as part of opening an issue if you run into problems.
Table mode only draws your models and skips the attributes and columns associated with your table. This feature is helpful for when you have lots of table columns and they are less helpful than seeing the tables and their relationships
generator erd {
provider = "prisma-erd-generator"
tableOnly = true
}
By default this module skips relation fields in the result diagram. For example fields userId
and productId
will not be generated from this prisma schema.
model User {
id String @id
email String
favoriteProducts FavoriteProducts[]
}
model Product {
id String @id
title String
inFavorites FavoriteProducts[]
}
model FavoriteProducts {
userId String
user User @relation(fields: [userId], references: [id])
productId String
product Product @relation(fields: [productId], references: [id])
@@id([userId, productId])
}
It can be useful to show them when working with RDBMS. To show them use includeRelationFromFields = true
generator erd {
provider = "prisma-erd-generator"
includeRelationFromFields = true
}
Thanks goes to these wonderful people (emoji key):
John Fay 🚧 💻 🤔 🐛 |
Jonas Strassel 🐛 💻 |
Steve Gray 💻 🤔 |
Jason Abbott 🐛 💻 |
Manuel Maute 🐛 💻 |
James Homer 💻 |
Jan Piotrowski 🐛 💻 👀 |
Luke Evers 💻 |
rikuyam 💻 |
Francis Manansala 🐛 |
Vitalii Yarmus 💻 |
Petri Julkunen 🐛 |
D-PONTARO 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!