feat(generator): add enabled field to toggle generators via env vars by quinnjr · Pull Request #29474 · prisma/prisma · GitHub
Skip to content

feat(generator): add enabled field to toggle generators via env vars#29474

Draft
quinnjr wants to merge 1 commit intoprisma:mainfrom
quinnjr:feature/generator-env-toggle
Draft

feat(generator): add enabled field to toggle generators via env vars#29474
quinnjr wants to merge 1 commit intoprisma:mainfrom
quinnjr:feature/generator-env-toggle

Conversation

@quinnjr
Copy link
Copy Markdown

@quinnjr quinnjr commented Apr 15, 2026

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 enabled field to generator blocks that works with env() so you can do something like enabled = 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

  • Added enabled?: EnvValue to GeneratorConfig in @prisma/generator
  • resolveEnabledField in getConfig.ts resolves the env var value during config loading, same pattern as resolveBinaryTargets
  • isGeneratorEnabled utility checks the resolved value and filterGenerators skips disabled ones with an info log
  • Unit tests for the utility and integration tests for the full getGenerators flow

Happy to adjust anything, this has been working well for us internally and figured it might be useful upstream too.

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
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 15, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants