I'm trying to create a different database name per...
# orm-help
j
I'm trying to create a different database name per branch to make sure we can test different branches in isolation. Is it possible to extend/compose the environment variable for
DATABASE_URL
?
Copy code
datasource db {
  provider = "postgresql"
  url      = env(`postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${BRANCH_NAME}?schema=public`)
}
According to the docs, we either set the full string, or a single environment variable (but in this case we want to read the branch name for each environment)
👀 1
n
Hi @Jose 👋 Did you had a chance to look at this section on Expanding environment variables?
j
Hi @Nurul yes I did, but it doesn't look like it supports composing the url based on several individual environment variables. Do you think it does?
n
Can you do something like this to compose url based on different environment variables?
Copy code
DATABASE_USERNAME=test
DATABASE_PASSWORD=test
DATABASE_SCHEMA=public
DATABASE_NAME=test
DATABASE_URL=postgresql://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@localhost:5432/${DATABASE_NAME}?schema=${DATABASE_SCHEMA}
v
👋 Hello @Jose - did you have a chance to check Nurul's suggestion? Let us know if you still need any help!
j
Hi @Nurul indeed I can do that on my local machine but unfortunately many cloud providers (like Vercel) don't allow to compose / extend environment variables 😓
n
Hmm, In that case how does your current workflow look like? Do you create different environment variables for every branch?
j
Yes, since we would like to use a different DB name for each branch we generate a different. Normally branch name is normally exposed by most providers