Skip to content

feat(sdk): load .env from project root#3971

Merged
timsuchanek merged 8 commits intomasterfrom
feat/resolve-env-project-root
Oct 21, 2020
Merged

feat(sdk): load .env from project root#3971
timsuchanek merged 8 commits intomasterfrom
feat/resolve-env-project-root

Conversation

@williamluke4
Copy link

@williamluke4 williamluke4 commented Oct 20, 2020

closes #3720

How it will work

  1. Load .env from project root
  2. Load first .env from possible schema locations and throw if there are env clashes with root .env
    1. Read location from schema arg --schema
    2. Read location from pkgJSON "prisma": {"schema": "/path/to/schema.prisma"}
    3. Read from default location ./prisma/.env

TODO

  • Refactor Code
  • Update Snapshots
  • Write Tests for new use case
  • Write Tests for .env conflicts
  • Final Clean Up

@williamluke4 williamluke4 changed the title feat(sdk): load .env from proect root feat(sdk): load .env from project root Oct 20, 2020
@williamluke4 williamluke4 force-pushed the feat/resolve-env-project-root branch 2 times, most recently from 378118b to 4727134 Compare October 20, 2020 14:19
@williamluke4 williamluke4 added this to the Release 2.10.0 milestone Oct 20, 2020
@Jolg42 Jolg42 self-requested a review October 20, 2020 16:14
@williamluke4 williamluke4 force-pushed the feat/resolve-env-project-root branch 2 times, most recently from 6d03e3b to 92a5c76 Compare October 21, 2020 08:13
@Jolg42 Jolg42 requested a review from timsuchanek October 21, 2020 09:43
@Jolg42
Copy link
Contributor

Jolg42 commented Oct 21, 2020

I will need to play with it locally I think to get the full experience

@williamluke4 williamluke4 force-pushed the feat/resolve-env-project-root branch from 6efc55d to 4467b53 Compare October 21, 2020 10:27
@williamluke4 williamluke4 removed the request for review from matthewmueller October 21, 2020 12:19
@williamluke4 williamluke4 force-pushed the feat/resolve-env-project-root branch from b9fd5f5 to 0a1b3cc Compare October 21, 2020 13:04
@timsuchanek
Copy link
Contributor

Once this is green, we can merge :)

@williamluke4 williamluke4 force-pushed the feat/resolve-env-project-root branch from 0a1b3cc to f3af22f Compare October 21, 2020 14:31
@timsuchanek timsuchanek merged commit 3c021d9 into master Oct 21, 2020
@timsuchanek timsuchanek deleted the feat/resolve-env-project-root branch October 21, 2020 14:45
Jolg42 added a commit that referenced this pull request Oct 21, 2020
* master:
  feat(sdk): load .env from project root (#3971)
  chore: Integration/prisma/engines (#3942)

/**
* Tries load env variables
* 1. Load .env from project root
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order in the code seems different? It seems like "Load .env from project root" happens last?

Copy link
Author

@williamluke4 williamluke4 Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this needs to be updated I thought I had

schemaEnvPathFromArgs, // 1 - Check --schema directory for .env
schemaEnvPathFromPkgJson, // 2 - Check package.json schema directory for .env
'./prisma/.env', // 3 - Check ./prisma directory for .env
'./.env' // 4 - Check cwd for .env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have missed something, but for 4, I think we'd want to check the same dir as where your package.json resides, rather than cwd.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for loading the env var from your project root would cover that case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Allow .env in the project root with the Prisma Schema somewhere else

4 participants