8 months ago
Hello hi!
This is my first time using railway or any online hosting service. So please don’t mind the dumb question! But if I have a script that I want to execute only once (e.g. creating database tables or preloading into tables) what’s the best way to go about doing this? It doesn’t feel right putting it in build then removing it and also doesn’t feel right adding a service and a new github repository either.
Thanks in advance!
11 Replies
8 months ago
Hello!
Welcome to Railway!
Since your example only mentioned database actions, I think this would be best achieved by using railway run locally.
This will allow you to run the script locally but with the service environment variables available.
Ooh that is neat thank you :D
I’m also curious if you’re able to share the same volume with a different service? Primarily the filebrowser since sometimes I’d want to check the files inside manually
8 months ago
We don't support shared services yet.
But if you just wanna look and manage the files, you can ssh in with railway ssh
Oo thank you - I've been trying and testing railway run as you suggested, but running into getaddrinfo ENOTFOUND postgres.railway.internal error, but not sure what I'm doing wrong

8 months ago
You would need to use the public database URL when running the command locally
8 months ago
postgres.railway.internal is an internal URL, perhaps you have the code using the wrong variables?
I'm not sure, I'm using postgres default variables, and referencing process.env.DATABASE_PUBLIC_URL
8 months ago
To run one time script like database init. I use either 2 ways:
1. railway cli to: railway ssh and run it
2. mount application location with volume (in Railway mount app/script) . create script folder under your root project. and run it via railway ssh or build command when you deploy.