Automatically Linking Postgres on PR Environment

I'm working on setting up my app to use PR Environments. It's a Nextjs app which uses a Railway node service and a Postgres service. Whenever a new PR environment is created it seems I have to manually go in and link my database url. DATABASE_URL populates as an environment variable but the value is "empty string". Is it possible to configure my PR environments to automatically link the newly spun up postgres instance?
11 Replies
Brody
Brody13mo ago
are you using variable references on the production branch?
caesarbeef
caesarbeefOP13mo ago
Yes, I believe I am
caesarbeef
caesarbeefOP13mo ago
I also did not select a "base" environment. However, most env vars seemed to copy themselves over from prod anyway
No description
caesarbeef
caesarbeefOP13mo ago
I just tried changing the base environment to production and creating a new PR environment - fwiw that didn't seem to change my DATABSE_URL from being an empty string
caesarbeef
caesarbeefOP13mo ago
Hate to spam the chat. But this might be why - the postgres service on my PR environments don't seem to have any environment variables. I don't totally understand that as I thought they would just come along with any postgres service.
No description
Brody
Brody13mo ago
yeah railway is aware this isnt a good dx, they will be looking to improve this flow
marko
marko13mo ago
hey! I have the same question -- have you found a fix?
caesarbeef
caesarbeefOP13mo ago
ah cool. Do you have any recommendations on how to use PR environments now? Is it just manually configuring the postgres credentials on each PR environment? i have not, unfortunately
Brody
Brody13mo ago
I have no clue, I don't use them myself, too complicated for me
Clem
Clem13mo ago
I'm having this issue as well, I don't understand how to have a Postgres service in my PR deployments, the service starts with "no service variables", so it's not available to my app Am I supposed to create share variables on staging and prod so my PR envs can inherit them ? That seems like a bad idea, I don't want my PR envs to use the same database as their base environment. What if I have a data migration in my PR ? What I expected is that my PR would just spin up a new database service (ideally cloned from the base env) but isolated
Want results from more Discord servers?
Add your server