a year ago
I have a question about connecting to postgresql service, when connecting to db in building phase, it will throw an error Can't reach database server at postgres.railway.internal:5432.
After searching the community doc, it causes by the private network couldn't use in building time, and should use public url such as DATABASE_PUBLIC_URL , but I don't know how to use DATAASE_PUBLIC_URL in building time, and using DATABASE_URL in run time.
5 Replies
a year ago
Hi there, you should be able to just refer to the DATABASE_PUBLIC_URL during build time. If you need to refer to it from a different service, just prepend it with the service name that you want it from - for example if you are referring to it during build phase of your backend, but the public URL is in the "Postgres" service you'd refer to it as Postgres.DATABASE_PUBLIC_URL as a referenced variable.
Status changed to Awaiting User Response Railway • over 1 year ago
a year ago
But the prisma uses DATABASE_URL from env variable, I have no idea how to change the DATABASE_URL in the backend service during build phase.
Status changed to Awaiting Railway Response Railway • over 1 year ago
a year ago
You'd reassign the variable, something like this in your build (say if you were running migrations in a separate migration:
[phases.migration]
dependsOn = ['install']
cmds = ['DATABASE_URL=$DATABASE_PUBLIC_URL npm run migrations'] # or whatever the your migration command isStatus changed to Awaiting User Response Railway • over 1 year ago
a year ago
Thanks for your reply. I have another question, I saw that v2 runtime could call private url, but how could I check my runtime is v2 or not?
Status changed to Awaiting Railway Response Railway • over 1 year ago
a year ago
Neither the V1 or the V2 runtime can call the private URL during build.
But if you see logs like "starting container" those would indicate you are on the V2 runtime.
Status changed to Awaiting User Response Railway • over 1 year ago
7 months ago
This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!
Status changed to Solved Railway • 7 months ago