Problem
By default when we initialize a Prisma project, we write an environment file to prisma/.env. This layout works for us but is unusual and incompatible with projects (e.g. next.js, blitz, redwood, create-react-app projects) that assume .env is in the project root.
If you try moving prisma/.env into the project root, you'd also need to move prisma/schema.prisma to the project root. This approach is documented, but subtle.
For context, there are two components that rely on .env:
- The CLI when introspecting and migrating.
- The generated database client when connecting to the database.
Suggested solution
I'd suggest we change our defaults from prisma/.env and prisma/schema.prisma to .env and schema.prisma. If someone already has an .env file, we append our default environment variable (DATABASE_URL) to the bottom of their existing .env file.
Alternatives
Do nothing
Don't change anything. Add a bit of documentation saying how you can make Prisma work with your existing .env file.
Initialize to .env and prisma/schema.prisma
prisma init could also write .env and prisma/schema.prisma instead of writing both files to the project root. I don't really see a reason to create a subdirectory with only 1 file (by default), but I also don't have strong opinions on this.
Related
Problem
By default when we initialize a Prisma project, we write an environment file to
prisma/.env. This layout works for us but is unusual and incompatible with projects (e.g. next.js, blitz, redwood, create-react-app projects) that assume.envis in the project root.If you try moving
prisma/.envinto the project root, you'd also need to moveprisma/schema.prismato the project root. This approach is documented, but subtle.For context, there are two components that rely on
.env:Suggested solution
I'd suggest we change our defaults from
prisma/.envandprisma/schema.prismato.envandschema.prisma. If someone already has an.envfile, we append our default environment variable (DATABASE_URL) to the bottom of their existing.envfile.Alternatives
Do nothing
Don't change anything. Add a bit of documentation saying how you can make Prisma work with your existing
.envfile.Initialize to
.envandprisma/schema.prismaprisma initcould also write.envandprisma/schema.prismainstead of writing both files to the project root. I don't really see a reason to create a subdirectory with only 1 file (by default), but I also don't have strong opinions on this.Related