Skip to content

Adjust prisma init to write to .env instead of prisma/.env #3721

@matthewmueller

Description

@matthewmueller

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions