Crashed after migration to new DB

I have a project with a Postgres DB and 2 services: one for frontend and one for backend. I migrated to the new DB as Railway requested, and now the backend repository is crashing. The project is: https://railway.app/project/c28866fd-5fa3-41e6-8ebd-1ab29b18f9c9
Railway
Railway
Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.
Solution:
seems like you hardcoded your database variables somewhere, please use reference variables https://docs.railway.app/guides/variables#referencing-another-services-variable
Jump to solution
68 Replies
Percy
Percy11mo ago
Project ID: c28866fd-5fa3-41e6-8ebd-1ab29b18f9c9
Brody
Brody11mo ago
did the migration finish without errors? logs of the crashed service please https://bookmarklets.up.railway.app/log-downloader/
Nicolás Bonder
Nicolás BonderOP11mo ago
Yes, I actually I checked and it was working well, so I deleted the legacy postgress and then it crashed
Solution
Brody
Brody11mo ago
seems like you hardcoded your database variables somewhere, please use reference variables https://docs.railway.app/guides/variables#referencing-another-services-variable
Nicolás Bonder
Nicolás BonderOP11mo ago
I just used variables in my .env file. Should I changed there or do you mean in Railway service?
Brody
Brody11mo ago
use service variables, make sure you are using references. never use a .env file when on railway, if its in your repo, delete it and add it to your .gitignore please
Nicolás Bonder
Nicolás BonderOP11mo ago
Yes, I have it in my gitignore, that why I think it doesnt care what I do there. So, where should I use the reference variables? I think I understand the problem. I have to go to the backend service and paste the new DATABASE_URL that I have in the new Postgres service
Nicolás Bonder
Nicolás BonderOP11mo ago
Now it is not crashing, but in the app I cant see the products: https://grooveticket.up.railway.app/
GROOVE TICKET
GROOVE TICKET
Adam
Adam11mo ago
This seems like a code issue. Your app is starting, maybe it’s having issues pulling from the db? do you log if the db was connected to successfully?
Nicolás Bonder
Nicolás BonderOP11mo ago
It just chrashed again
Brody
Brody11mo ago
please read the docs i have linked, you should not need to be pasting anything from your postgres service please use reference variables
Nicolás Bonder
Nicolás BonderOP11mo ago
I dont understand how to use reference variables
Brody
Brody11mo ago
that is what the docs are for, please read the docs i have linked, there is an example
Nicolás Bonder
Nicolás BonderOP11mo ago
Should I do this ${{ VARIABLENAME }} in the backend serivce or what should I do
Brody
Brody11mo ago
please look at the example the docs gives do not skim read, read the entire section for Referencing another service's variable
Nicolás Bonder
Nicolás BonderOP11mo ago
Yes, I already did that, but it keep crushing.
No description
Nicolás Bonder
Nicolás BonderOP11mo ago
And I also did it for DATABASE_URL In the backend service there is a variable that there is not in the DB: DB_DEPLOY, so I cant use it as reference and I dont know what should I do
Brody
Brody11mo ago
what variable do you use in code to connect to the database?
Nicolás Bonder
Nicolás BonderOP11mo ago
I have this code:
const { DB_DEPLOY } = process.env;

const sequelize = new Sequelize(DB_DEPLOY, { //Esto hace que se conecte a la DB de deploy, en Railway
dialect: 'postgres',
dialectOptions: {
ssl: setSSL
},
const { DB_DEPLOY } = process.env;

const sequelize = new Sequelize(DB_DEPLOY, { //Esto hace que se conecte a la DB de deploy, en Railway
dialect: 'postgres',
dialectOptions: {
ssl: setSSL
},
Brody
Brody11mo ago
then you need to name that variable (the left value) DB_DEPLOY while keeping the value on the right the same
Nicolás Bonder
Nicolás BonderOP11mo ago
Hi, I am back. I added in the Postgres service the variable DB_DEPLOY with the same value I have in the backend service. But the backend keep crashing. I was trying to find out why it is not connecting. In the backend service I added variables PGHOST and PGPORT. And I changed the value of NODE_ENV from TEST to PRODUCTION. But it is still failing and crashing.
Brody
Brody11mo ago
have you made this change I said? if so, please show me a screenshot definitely don't show me the rendered value deleting that because that's your database credentials show me the raw reference syntax please
Nicolás Bonder
Nicolás BonderOP11mo ago
what does it mean? Where is it? do you mean the raw editor?
Brody
Brody11mo ago
the edit button, show me the raw value for that variable
Nicolás Bonder
Nicolás BonderOP11mo ago
If I touch the edit button, you will see the same:
No description
Brody
Brody11mo ago
please use variable references like the docs page I linked above showed
Nicolás Bonder
Nicolás BonderOP11mo ago
No description
Brody
Brody11mo ago
please look at the example in the docs page I linked it has a very clear example
Nicolás Bonder
Nicolás BonderOP11mo ago
No description
Nicolás Bonder
Nicolás BonderOP11mo ago
Man, obviously I dont understand. Can you explain me?
Brody
Brody11mo ago
you use DB_DEPLOY in your code, therefore that is the only variable you need to focus on, I don't know how I could explain it better than the docs do, the example goes pretty in depth in my opinion have you expanded the example section so it shows you what variable references look like?
Nicolás Bonder
Nicolás BonderOP11mo ago
The docs doesnt explain nothing actually, . I am asking you to help me. According what I understand What I did is the same that there is in the example I saw in the doc
Nicolás Bonder
Nicolás BonderOP11mo ago
Yes, this:
No description
Nicolás Bonder
Nicolás BonderOP11mo ago
can you explain the difference because probably I am not seeing it
Brody
Brody11mo ago
you have not expanded the example section please look at the examples under this section https://docs.railway.app/guides/variables#referencing-another-services-variable
Nicolás Bonder
Nicolás BonderOP11mo ago
Instead of ${{Postgres.DATABASE_PRIVATE_URL}} should I write: ${{Postgres.DATABASE_PRIVATE_URL}} or is the same?
Brody
Brody11mo ago
yes that is the value you want. but are those two options you just asked not the exact same??
Nicolás Bonder
Nicolás BonderOP11mo ago
yes, looks the same but I wrote the second with `` as in the example please, please make an effort an try to explain me what I need to do instead of asking me to read a doc that I dont understand
Brody
Brody11mo ago
ignore the backticks, those are purely for style formatting
Nicolás Bonder
Nicolás BonderOP11mo ago
I see this example, but I dont know what I have to in my case.
No description
Brody
Brody11mo ago
I have already explained exactly what you needed to do. you are looking at the wrong example, why?
Nicolás Bonder
Nicolás BonderOP11mo ago
In postres service I have something similar, but is not the proble:
No description
Nicolás Bonder
Nicolás BonderOP11mo ago
No man, because I already added the DB_DEPLOY and added a value and is not working, so it is not what I need to do
Brody
Brody11mo ago
you did not use references, you hardcoded the actual value once you are using reference variables we can move on to debugging further, but for now that's what needs to be done
Nicolás Bonder
Nicolás BonderOP11mo ago
come, please help me. In backend service I am using reference, or I understand I use reference because I have this:
No description
Nicolás Bonder
Nicolás BonderOP11mo ago
Why it is not a reference variable?
Brody
Brody11mo ago
it is a reference variable, but the Postgres service you are referencing does not have a DB_DEPLOY variable to reference, so it is an invalid reference. please look at the example for the correct reference syntax that you need to use you had the correct value here, use that value
Nicolás Bonder
Nicolás BonderOP11mo ago
In the postgres service I have this:
No description
Nicolás Bonder
Nicolás BonderOP11mo ago
Can you tell me what should I write there if it is not correct?
Brody
Brody11mo ago
please remove it, you should not have needed to touch the variables on the postgres service itself
Nicolás Bonder
Nicolás BonderOP11mo ago
but if I remove that variable in the postgres service, I will not have a riable to refer from backend? So how I will conect?
Brody
Brody11mo ago
you need to reference the database url variable
Nicolás Bonder
Nicolás BonderOP11mo ago
which is?
Brody
Brody11mo ago
DATABASE_URL or DATABASE_PRIVATE_URL might be easier to choose the first variable. the example shows you how to use these variables in the reference syntax
Nicolás Bonder
Nicolás BonderOP11mo ago
come on!!!! please, help me!!! I am begging you the answer, dont send me to the example!!! I dont understand it!!!
Brody
Brody11mo ago
you had it right here, just the variable name was wrong (the name on the left) you where already 90% of the way there let's focus on this service first, you can see it's name in the top left
Nicolás Bonder
Nicolás BonderOP11mo ago
Yes, and you same the variable name is wrong. What should be the name_?
Brody
Brody11mo ago
your name of the variable should be the same as you use in your code
Nicolás Bonder
Nicolás BonderOP11mo ago
So I change DATABASE_PRIVATE_URL and put DB_DEPLOY
Brody
Brody11mo ago
if you are only talking about the variable name on the left input field, then yes
Nicolás Bonder
Nicolás BonderOP11mo ago
ok, and then I also change the name in the postgres service and use the variable reference
Brody
Brody11mo ago
please do not touch any variables on the postgres service
Nicolás Bonder
Nicolás BonderOP11mo ago
Finally! It is working Thanks
Brody
Brody11mo ago
no problem!
Luis Kurihara
Luis Kurihara11mo ago
look your dm
Brody
Brody11mo ago
please do not DM people here without asking first
Luis Kurihara
Luis Kurihara11mo ago
ok sorry
Want results from more Discord servers?
Add your server