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
Allow .env in the project root with the Prisma Schema somewhere else #3720
Comments
When calling the Prisma Client builder, it is possible to pass a URL parameter to replace what is already in the In my case for example, I have a monorepo in React and ApolloGraphQL. To be able to access the workspace If So you can keep the |
Yes!! 💯💯💯 We also need this for nice integration with Blitz. Also, with Blitz/Next, we use dotenv-flow which automatically picks up |
Hey @matthewmueller check out this it might be of help |
Planning outcome: @timsuchanek proposed to sit down and figure out some more detailed implications of doing that before actually tackling it. |
It would be amazing if we could have support for using the I'm working on a course that includes Prisma and it's currently a bit clunky to have two env files, or a symlink. |
Thanks for your feedback so far! @timsuchanek and I sat down today to discuss the details on how we could solve the following problems.
|
Thanks for working on this @matthewmueller! Unfortunately this proposal doesn't help the Blitz integration at all. And that's because by default we have This is also the recommended approach by Create React App, Next.js, and dotenv-flow. |
Thanks for your feedback @flybayer! I've opened a separate issue to discuss this feature further. |
I'm happy with the proposal, as long as the Prisma client will traverse up to the project root various levels. In my apps, the Prisma file lives in I also prefer not embedding the files into the prisma client that gets generated. Switching to different ENV's would be awesome to, but I'd love so see the project-level |
Right now we're thinking of resolving
This would mean that for
Does that work for you @beeman? |
@matthewmueller yes, it does! Currently I create a symlink from the root to where I have my schema.prisma :) |
Problem
Right now we support an optional
.env
file that must live next to yourschema.prisma
file in the same directory. This coupling is a bit surprising and is often incompatible with how people want to organize their project.Additionally, when you run
prisma init
, we write our env file toprisma/.env
alongsideprisma/schema.prisma
. This layout works for us but is unusual and incompatible with projects that assume.env
is in the project root. If you try movingprisma/.env
into the project root, you'll also need to moveprisma/schema.prisma
to the project root. This approach is documented, but subtle.For context, there are two components that rely on
.env
:Suggested solution
At the very least, we should allow
.env
in the project root and theschema.prisma
in aprisma/
directory. This will allow people to re-use their.env
that's already supported in Next.js, Redwood, Blitzjs, Create React App, etc.Alternatives
Decouple
.env
andschema.prisma
It's not clear to me why we have this coupling between
.env
andschema.prisma
in the first place. From my perspective,DATABASE_URL
being present by the time we connect.DATABASE_URL
is in the environment at the time of introspection.DATABASE_URL
is in the environment at the time of migration.The CLI calls
require('dotenv').config()
in the beginning of the run. The Client doesn't do anything and expects the application to load the environment.This would additionally allow us to properly support frameworks that use.env.test
,.env.production
. See #1717 for an example of this.This solution would be my preference because it additionally solves #1717.(See Sept 24 Update)Do nothing, suggest wrapping
Redwood & BlitzJS work around this problem by wrapping the Prisma CLI in their own CLI. This allows them to have the project structure they want without our limitations
I'm not advocating for this one, but it would solve the problem.
Related
prisma init
default: Adjustprisma init
to write to .env instead of prisma/.env #3721Updates
Sept 24
Decoupling wouldn't completely add support for
.env.test
and.env.production
in every case. For example, if you want to run the CLI with the test configuration (to migrate your test database), just callingrequire('dotenv').config()
would load.env
in all cases.I don't think there's much harm in using something like
require("dotenv-flow").config()
as @flybayer suggested in the CLI to switch based onNODE_ENV
.The text was updated successfully, but these errors were encountered: