prisma / studio

🎙️ The easiest way to explore and manipulate your data in all of your Prisma projects.
https://www.prisma.io/studio
1.86k stars 47 forks source link

Custom DB environment variable #706

Closed heymartinadams closed 3 months ago

heymartinadams commented 3 years ago

Describe the bug We use an environment variable manager (Doppler.com) rather than .env files. As such, our environment variable is currently not accessible to the Prisma Data Platform.

This obviously won’t let us use the Prisma Data Platform, since it cannot access our database.

Any solutions? Any workarounds?

sdnts commented 3 years ago

I don't think an easy workaround exists currently, this will have to be built as its own feature :D

sdnts commented 3 years ago

Out of curiosity, do you inject the database URL at runtime then?

sdnts commented 3 years ago

That would be cool! I'm only interested in how you're supplying the database URL to Prisma at build time :D

heymartinadams commented 3 years ago

We inject the database URL at build time via a custom build script. Inside that build script, the database URL variable gets created dynamically: Doppler CLI gets installed and run, then the NextJS build command is called using that dynamically-created variable. Here’s what happens:

// Packages
import shell from 'shelljs'

// This is run on Vercel
const ScriptBuild = async () => {
  shell.exec(
    `(curl -Ls https://cli.doppler.com/install.sh || wget -qO- https://cli.doppler.com/install.sh) | sh`
)

  const env = process.env.ENV

  const token = `DOPPLER_TOKEN_` + env.toUpperCase()

  shell.exec(`doppler setup --token ${process.env[token]} --config ${env}`)

  shell.exec(`prisma generate --schema=./prisma/${env}/schema.prisma`)

  shell.exec(`doppler run -- next build`)
}

ScriptBuild()