-
Notifications
You must be signed in to change notification settings - Fork 52
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
Option to ignore certain tables #82
Comments
Would it ignore tables and fields or just tables and relationships? I kind of like the @@ignore over the .prismaignore |
I'm personally interested in ignoring tables and relationships so far, which helps to narrow down the ERD by not having to many nodes and edges. Ignoring fields particularly may be interesting for some users though but I would rate this as a secondary goal. One could potentially salvage some of the So I was thinking about something like that: generator prisma-erd-generator {
...
ignore: "system_*, patter-2" // <- use regex or glob pattern here
}
model users {
...
settings @relation("system_settings" ...) // <- won't show in ERD
fields @relation("system_settings" ...) // <- won't show in ERD
}
model system_fields { // <- won't show in ERD
...
}
model system_settings { // <- won't show in ERD
...
} |
My current "solution" is the following script I call from // generate a "purified" ERD which only includes non-system tables.
const fs = require('fs')
const { spawnSync } = require('child_process')
const modelRegex = /model directus_.* {[^]*?\n}/gm
const propRegex = /^.*directus_.*[^{]$/gm
const knexRegex = /model knex_.* {[^]*?\n}/gm
const generatorRegex = /generator (client|erd) {[^]*?\n}/gm
function generatePureERD(inPath, outPath) {
console.log('Generating pure ERD from', inPath)
const contents = fs.readFileSync(inPath, 'utf8')
// Replace regex from schema
const pureSchema = contents
.replace(modelRegex, '')
.replace(propRegex, '')
.replace(knexRegex, '')
.replace(generatorRegex, '')
const customGenerator = `generator erd {
provider = "prisma-erd-generator"
output = "./pure-ERD.svg"
}
`
fs.writeFileSync(outPath, customGenerator + pureSchema)
// Now generate the pure ERD
spawnSync('prisma', ['format', `--schema=${outPath}`])
spawnSync('prisma', ['generate', `--schema=${outPath}`])
console.log('-> done')
}
const inPath = './prisma/schema.prisma'
// NOTE: The ERD will live relative to this file
const outPath = './docs/database/schema/pure-schema.prisma'
generatePureERD(inPath, outPath) I just though this could be a nice core feature and probably be valuable for more users so I decided it's time to get some feedback on this and see if anyone is interested. |
Personally I like the ignore param with regex patterns because it should stay separate from any future prisma updates. |
How about a flag/regex to ignore certain tables/relations?
I got some "system" tables that I don't really want to end up in the ERD but they will obviously be introspected by prisma.
What do you think of that? Could be a good complement for #72.
Related: prisma/prisma#807
The text was updated successfully, but these errors were encountered: