Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha #236

Merged
merged 5 commits into from
Aug 22, 2023
Merged

Alpha #236

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ERD.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ Options
- dark
- neutral

This option does not accept environment variables or other dynamic values. If you want to change the theme dynamically, you can use the `theme` option in the `mermaidConfig` option. See [Mermaid Configuration](#mermaid-configuration) for more information.

### 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.
Expand All @@ -95,12 +97,23 @@ generator erd {

### 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`.
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. There are two ways to disable this ERD generator.

1. Via environment variable

```bash
DISABLE_ERD=true
```

2. Via configuration

```prisma
generator erd {
provider = "prisma-erd-generator"
disabled = 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.

```dockerfile
Expand Down Expand Up @@ -202,6 +215,17 @@ generator erd {
}
```

### Mermaid configuration

Overriding the default mermaid configuration may be necessary to represent your schema in the best way possible. There is an example mermaid config [here](./example-mermaid-config.js) that you can use as a starting point. In the example JavaScript file, types are referenced to view all available options. You can also view them [here](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts). The most common use cases for needing to overwrite mermaid configuration is for theming and default sizing of the ERD.

```prisma
generator erd {
provider = "prisma-erd-generator"
mermaidConfig = "mermaidConfig.json"
}
```

### Puppeteer configuration

If you want to change the configuration of Puppeteer, create a [Puppeteer config file (JSON)](https://pptr.dev/guides/configuration#configuration-files) and pass the file path to the generator.
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions __tests__/disabled-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as child_process from 'child_process';
import fs from 'fs';

test('disabled-config.prisma', async () => {
const fileName = 'disabled-config.svg';
const folderName = '__tests__';
child_process.execSync(`rm -f ${folderName}/${fileName}`);
child_process.execSync(
`npx cross-env prisma generate --schema ./prisma/disabled-config.prisma`
);
const exists = fs.existsSync(`${folderName}/${fileName}`);
expect(exists).toBe(false);
});
13 changes: 13 additions & 0 deletions __tests__/disabled-env.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as child_process from 'child_process';
import fs from 'fs';

test('disabled-env.prisma', async () => {
const fileName = 'disabled.svg';
const folderName = '__tests__';
child_process.execSync(`rm -f ${folderName}/${fileName}`);
child_process.execSync(
`cross-env DISABLE_ERD=true prisma generate --schema ./prisma/disabled-env.prisma`
);
const exists = fs.existsSync(`${folderName}/${fileName}`);
expect(exists).toBe(false);
});
20 changes: 0 additions & 20 deletions __tests__/disabled.ts

This file was deleted.

File renamed without changes.
17 changes: 17 additions & 0 deletions example-mermaid-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @type {import('mermaid').MermaidConfig} */
const config = {
deterministicIds: true,
maxTextSize: 90000,
er: {
/**
* When this flag is set to `true`, the height and width is set to 100%
* and is then scaled with the available space.
* If set to `false`, the absolute space required is used.
*
*/
useMaxWidth: false,
},
theme: 'default',
};

module.exports = config;
Loading