Giter Club home page Giter Club logo

prisma-minimal-erd-generator's Introduction

Prisma Entity Relationship Diagram Generator

All Contributors

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

Example ER Diagram

Versions

  • Prisma >= 4 use 1.x.x
  • Prisma <4 use 0.11.x

Options

Additional configuration

Output

Change output type and location

Usage

generator erd {
  provider = "prisma-erd-generator"
  output = "../ERD.svg"
}

Extensions

  • svg (default: ./prisma/ERD.svg)
  • png
  • pdf
  • md

Theme

Theme selection

Usage

generator erd {
  provider = "prisma-erd-generator"
  theme = "forest"
}

Options

  • default (default)
  • forest
  • dark
  • neutral

mmdcPath

In order for this generator to succeed you must have mmdc installed. This is the mermaid cli tool that is used to generate the ERD. By default the generator searches for an existing binary file at /node_modules/.bin. If it fails to find that binary it will run find ../.. -name mmdc to search through your folder for a mmdc binary. If you are using a different package manager or have a different location for your binary files, you can specify the path to the binary file.

generator erd {
  provider = "prisma-erd-generator"
  theme = "forest"
  mmdcPath = "node_modules/.bin"
}

Disabled

You won't always need to generate a new ERD. For instance, when you are building your docker containers you often run prisma generate and if this generator is included, odds are you aren't relying on an updated ERD inside your docker container. It also adds additional space to the container because of dependencies such as puppeteer. To disabled running this generator just add an environment variable to the environment running prisma generate.

DISABLE_ERD=true

Another option used is to remove the generator lines from your schema before installing dependencies and running the prisma generate command. I have used sed to remove the lines the generator is located on in my schema.prisma file to do so. Here is an example of the ERD generator being removed on lines 5-9 in a dockerfile.

# remove and replace unnecessary generators (erd generator)
# Deletes lines 5-9 from prisma/schema.prisma
RUN sed -i '5,9d' prisma/schema.prisma

Debugging

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 only mode

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
}

Ignore enums

If you enable this option, enum entities will be hidden. This is useful if you want to reduce the number of entities and focus on the tables and their columns and relationships.

generator erd {
  provider = "prisma-erd-generator"
  ignoreEnums = true
}

Include relation from field

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
}

Disable emoji output

The emoji output for primary keys (๐Ÿ—๏ธ) and nullable fields (โ“) can be disabled, restoring the older values of PK and nullable, respectively.

generator erd {
  provider     = "prisma-erd-generator"
  disableEmoji = true
}

Puppeteer configuration

If you want to change the configuration of Puppeteer, create a Puppeteer config file (JSON) and pass the file path to the generator.

generator erd {
  provider = "prisma-erd-generator"
  puppeteerConfig = "../puppeteerConfig.json"
}

Issues

Because this package relies on mermaid js and puppeteer issues often are opened that relate to those libraries causing issues between different versions of Node.js and your operating system. As a fallback, if you are one of those people not able to generate an ERD using this generator, try running the generator to output a markdown file .md first. Trying to generate a markdown file doesn't run into puppeteer to represent the contents of a mermaid drawing in a browser and often will succeed. This will help get you a functioning ERD while troubleshooting why puppeteer is not working for your machine. Please open an issue if you have any problems or suggestions.

๐Ÿ”ด ARM64 Users ๐Ÿ”ด

Puppeteer does not yet come shipped with a version of Chromium for arm64, so you will need to point to a Chromium executable on your system. More details on this issue can be found here.

MacOS Fix:

Install Chromium using Brew:

brew install --cask --no-quarantine chromium

You should now see the path to your installed Chromium.

which chromium

The generator will use this Chromium instead of the one provided by Puppeteer.

Other Operating Systems:

This can be fixed by either:

  • Setting the executablePath property in your puppeteer config file to the file path of the Chromium executable on your system.
  • Setting the following global variables on your system
    PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
    PUPPETEER_EXECUTABLE_PATH=path_to_your_chromium
    

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

John Fay
John Fay

๐Ÿšง ๐Ÿ’ป ๐Ÿค” ๐Ÿ›
Jonas Strassel
Jonas Strassel

๐Ÿ› ๐Ÿ’ป
Steve Gray
Steve Gray

๐Ÿ’ป ๐Ÿค”
Jason Abbott
Jason Abbott

๐Ÿ› ๐Ÿ’ป
Manuel Maute
Manuel Maute

๐Ÿ› ๐Ÿ’ป
James Homer
James Homer

๐Ÿ’ป
Jan Piotrowski
Jan Piotrowski

๐Ÿ› ๐Ÿ’ป ๐Ÿ‘€
Luke Evers
Luke Evers

๐Ÿ’ป
rikuyam
rikuyam

๐Ÿ’ป
Francis Manansala
Francis Manansala

๐Ÿ›
Vitalii Yarmus
Vitalii Yarmus

๐Ÿ’ป
Petri Julkunen
Petri Julkunen

๐Ÿ›
D-PONTARO
D-PONTARO

๐Ÿ’ป
Stephen Ramthun
Stephen Ramthun

๐Ÿ“–
Tristan Chin
Tristan Chin

๐Ÿ’ป
Brandin Canfield
Brandin Canfield

๐Ÿ’ป
kota marusue
kota marusue

๐Ÿ“–
Lucia
Lucia

๐Ÿ›
Austin Ziegler
Austin Ziegler

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.