{{ message }}
feat(generator): add enabled field to toggle generators via env vars#29474
Draft
quinnjr wants to merge 1 commit intoprisma:mainfrom
Draft
feat(generator): add enabled field to toggle generators via env vars#29474quinnjr wants to merge 1 commit intoprisma:mainfrom
quinnjr wants to merge 1 commit intoprisma:mainfrom
Conversation
lets you slap an `enabled = env("WHATEVER")` on a generator block and
control whether it runs or not at generate time, which is something
i've wanted for a while when working with multiple generators where
you don't always need all of them running locally
falsy values (false, 0, no, off, empty string) disable the generator
and everything else keeps it enabled, defaults to enabled if the env
var isn't set so nothing breaks for existing schemas
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

At Lexmata we maintain a single shared Prisma schema as the source of truth across all our repos and microservices, both TypeScript and Go, and one thing that's been bugging us for a while is that we can't selectively turn generators on or off without maintaining separate schema files or doing hacky workarounds. We have generators for things like Ent modules that we need in our Go projects but absolutely do not want dragging into our TypeScript services and adding unnecessary dependency bloat, and right now there's no clean way to handle that from a single schema.
This PR adds an
enabledfield to generator blocks that works withenv()so you can do something likeenabled = env("GENERATE_ENT")and just control what runs at generate time through environment variables. Falsy values (false, 0, no, off, empty string) disable the generator, anything else or unset keeps it enabled so existing schemas aren't affected at all.What changed
enabled?: EnvValuetoGeneratorConfigin@prisma/generatorresolveEnabledFieldingetConfig.tsresolves the env var value during config loading, same pattern asresolveBinaryTargetsisGeneratorEnabledutility checks the resolved value andfilterGeneratorsskips disabled ones with an info loggetGeneratorsflowHappy to adjust anything, this has been working well for us internally and figured it might be useful upstream too.