Skip to content

ENV Variables with SQLite #1142

@jlarmstrongiv

Description

@jlarmstrongiv

I was trying out how the .env settings worked with schema.prisma.

Setting the url of a sqlite database dynamically using an env variable does not work.

datasource sqlite {
  provider = "sqlite"
  url      = env("SQLITE_FILE")
  enabled  = true
}

That schema throws an error

Error:
Invalid `photon.()` invocation in /Users/jlarmst/Downloads/boombox/prisma/seed.js:5:36



undefined target="exit" timestamp="2019-12-14T22:53:34.018Z" fields={"message":"1"}
    at PhotonFetcher.<anonymous> (/Users/jlarmst/Downloads/boombox/node_modules/@prisma/photon/index.js:65:27)
    at Generator.throw (<anonymous>)
    at rejected (/Users/jlarmst/Downloads/boombox/node_modules/@prisma/photon/index.js:6:65)
(node:2244) UnhandledPromiseRejectionWarning: Error: undefined target="exit" timestamp="2019-12-14T22:53:34.018Z" fields={"message":"1"}
    at NodeEngine.engineReady (/Users/jlarmst/Downloads/boombox/node_modules/@prisma/photon/runtime/index.js:3533:23)
    at async /Users/jlarmst/Downloads/boombox/node_modules/@prisma/photon/runtime/index.js:3456:21
(node:2244) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2244) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

However, defining two sqlite datasources with the enabled property set in the .env does work.

datasource sqlite {
  provider = "sqlite"
  url      = "file:dev2.db"
  enabled  = env("SQLITE_ENABLED")
}

Note that the env has to be a boolean, or it crashes. The documentation shows setting the enabled env to the same url variable.

Error

Error: Schema parsing
error: Expected a boolean value, but failed while parsing "file:./dev2.db": fail
ed to parse bool.
  -->  schema.prisma:8
   |
 7 |   url      = "file:dev.db"
 8 |   enabled  = env("SQLITE_URL")
 9 | }
   |
    at Object.<anonymous> (/Users/jlarmst/env/lib/node_modules/prisma2/build/ind
ex.js:74991:23)
    at Generator.throw (<anonymous>)
    at rejected (/Users/jlarmst/env/lib/node_modules/prisma2/build/index.js:7488
6:65)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions