R
Railway6mo ago
Natchi

Prisma can't reach database server (during build)

Hello, I would like when deploying my application to synchronize the migrations with the database that I also have on railway. So I added this command during the build.
"build": "prisma migrate deploy && nest build"
"build": "prisma migrate deploy && nest build"
but unfortunately I have this error. I also had it when I put it on the script to start the application after building, and it only worked when I restarted the server.
No description
34 Replies
Percy
Percy6mo ago
Project ID: 2b4c4fbf-3975-4801-970c-47c4c97d9fe0
Brody
Brody6mo ago
the private network is not available during build yet
Natchi
NatchiOP6mo ago
So why I had the error also when commanding to start the application? for DATABASE_URL variable i use the ref to ${{Postgres.DATABASE_PRIVATE_URL}} so i have to use ${{Postgres.DATABASE_URL}}?
Brody
Brody6mo ago
because you would need to have a 3 second delay before attempting to connect to a private service yes you would have to use the public url if you want to run migrations during build, or continue using the private network and run the migrations at runtime before starting your app
Natchi
NatchiOP6mo ago
what configuration do you recommend?
Brody
Brody6mo ago
before you change anything, try enabling their new builder, I forget if it is a part of the private network, but I know it would be the end goal so maybe it's already implemented https://railway.app/changelog/2024-05-24-builder-v2-beta
Natchi
NatchiOP6mo ago
ok i try i need a nixpacks.toml ?
Brody
Brody6mo ago
not necessarily, why do you ask?
Natchi
NatchiOP6mo ago
it does not take the configuration on railway directly so he sends this back to me Error: No start command could be found
Brody
Brody6mo ago
I'm not sure what you mean, you need to set that variable as a service variable, have you? How were you previously setting your start command?
Natchi
NatchiOP6mo ago
it does not use the custom start command that I put in the parameters of my service I did not change this command when I changed the builder version I would therefore like to create a nixpacks configuration file, but the problem is that I don't know what to put in nixPckgs apart from nodejs because when I don't use the nixpacks file, by default it uses nodejs, npm and openssl
Brody
Brody6mo ago
so you already have a nixpacks.toml file?
Natchi
NatchiOP6mo ago
I tried to put it on to see what we could do, but I took it off
Brody
Brody6mo ago
okay, you're all over the place and I don't know what the current issue is. so let's start off without a nixpacks.toml file, what kind of app do you have?
Natchi
NatchiOP6mo ago
i have a nestjs app my question is but is it recommended to do the migration during the build or start?
Brody
Brody6mo ago
start because then you can use the private network. but I have asked you to try running the migration during build with the v2 builder
Natchi
NatchiOP6mo ago
yes but i need nixpacks.toml to run the v2 builder
Brody
Brody6mo ago
why is that
Natchi
NatchiOP6mo ago
I'm going to put the whole context back I had the bug concerning prisma which could not connect to my database during the build via the internal url, because during the build there is no access to the internal network. You therefore suggested that I use the builder v2 which could potentially solve this problem. So I activated the builder v2 via the variables. But I noticed that it does not find a start command even though I put a custom start command on the settings of my backend service (on railway directly). So I wanted to create a nixpacks.toml configuration file to define the build, start, etc. commands... But the problem is that I noticed that I didn't know what to put in nixPcks in the setup phase. Because without a nixpacks.toml file, it has nodejs_20, npm_9 and openssl as default. And in mine I just put nodejs, and I didn't know if I should put other things. So I'm just wondering if it's better to migrate my database during start or during build. To me this makes more sense during the build. But in this case, I would like someone to explain the nixpacks.toml configuration file to me. @Brody If you have any questions do not hesitate. sorry I wasn't on my pc before
Brody
Brody6mo ago
I'm sorry but I don't currently have the time to read all that, instead I would greatly appreciate if you could directly answer my previous question
Natchi
NatchiOP6mo ago
I noticed that it does not find a start command even though I put a custom start command on the settings of my backend service (on railway directly).
Natchi
NatchiOP6mo ago
No description
Natchi
NatchiOP6mo ago
but the builder v2 return this
Natchi
NatchiOP6mo ago
No description
Brody
Brody6mo ago
thank you for this clear and concise answer, try adding a start script to your package.json instead
Natchi
NatchiOP6mo ago
I see that it deletes lots of files, why?
60 store paths deleted, 512.58 MiB freed
this v2 is used to take up less space for snapshots?
Brody
Brody6mo ago
the new builder is much more verbose, I don't think you need to pay much mind to what it prints
Natchi
NatchiOP6mo ago
it takes much longer
Natchi
NatchiOP6mo ago
No description
Natchi
NatchiOP6mo ago
it fail
Natchi
NatchiOP6mo ago
No description
Natchi
NatchiOP6mo ago
after 10min
Brody
Brody6mo ago
with what error
Natchi
NatchiOP6mo ago
nothing it's the last logs i come back to build v1 and i create this nixpacks.toml file
[phases.build]
cmds = ['npm run build']

[start]
cmd = 'sleep 3 && npm run prisma migrate deploy && npm run start'
[phases.build]
cmds = ['npm run build']

[start]
cmd = 'sleep 3 && npm run prisma migrate deploy && npm run start'
Want results from more Discord servers?
Add your server