The Railway way of adding external databases
martin-carlsson
PROOP

10 months ago

I have a project where a Neon some, but not all, of the services need access to a Neon database.

What is the "Railway way" of adding external dependencies?

I'm considering creating a empty service, put the Neon connection string in that, and then use reference variables in the services that needs to have access to the database.

Solved$10 Bounty

Pinned Solution

10 months ago

That's a good idea, though you don't need to create an empty service to do that, there is already a feature for exactly this kind of use-case called shared variables. It lets you define a variable on the project-scope* that any service can access (*with project scope, i really mean project environment scope, but you get the idea)

So in your case you'll want to add the Neon database connection URL as a shared variable

You can read more shared variables here: https://docs.railway.com/guides/variables#shared-variables

3 Replies

10 months ago

That's a good idea, though you don't need to create an empty service to do that, there is already a feature for exactly this kind of use-case called shared variables. It lets you define a variable on the project-scope* that any service can access (*with project scope, i really mean project environment scope, but you get the idea)

So in your case you'll want to add the Neon database connection URL as a shared variable

You can read more shared variables here: https://docs.railway.com/guides/variables#shared-variables


martin-carlsson
PROOP

10 months ago

Thanks!

I'll take that approach! I can see that it also make it easy to have different environments with different variables.

Though, I do find it cool to have the visual representation that includes a database.

Attachments


10 months ago

That's fair, if you like the visual representation then an empty service is completely fine, either way should work for your use-case


Status changed to Solved brody 10 months ago


Loading...