Best Practices for Local Development with Next.js, Prisma, and PostgreSQL on Railway

aneeshsoniHOBBY

5 months ago

Hi everyone,

I’m working on a Next.js app with Prisma and PostgreSQL, and I’m curious about the typical workflow or best practices when working locally with these tools.

  1. Local PostgreSQL vs. Staging Environment: Do most developers spin up a local instance of PostgreSQL and have Prisma connect directly to that local database during development? Or is it more common to set up a "staging" environment on a platform like Railway and reference that database instead? If you're using the "staging" environment how do you promote your changes to kickoff a process for the production env?

  2. Egress Fees: If the approach is to use a staging environment on Railway, that would require connecting to the PostgreSQL database via a public URL. This would result in egress fees, correct? How do folks manage this when developing locally?

Thanks for the help!

Solved

5 Replies

5 months ago

Hello Aneesh!

  1. I personally have witnessed more people use a staging or development environment on Railway just because that makes it quite easy to setup a database and a duplicate of their production environment. And then you can use environment syncing to sync config to and from staging.

  2. Working locally with a database on Railway would mean needing to connect to the database and thus you would incur egress, but you would only incur that egress during development, and chances are what you are doing during development isn't using the database as heavily as a production app would be. So I would say they are negligible at best.


aneeshsoniHOBBY

5 months ago

Thanks for the response Brody, I think that generally checks out with my intuition.

1. Is it possible to copy over some or all of the data from the production database into the development environment? I was under the impression that "sync" would do this for me but that doesn't seem like it's the case. I have a pg_vector database in the production environment and want to use it for local dev (currently just pointing to the production db credentials).


5 months ago

Sync only syncs the config of the environment.

To transfer Postgres data you would need to pg_dump and pg_restore.


aneeshsoniHOBBY

5 months ago

Sweet, thanks for the help Brody!


5 months ago

No problem!


Status changed to Solved brody 5 months ago


Best Practices for Local Development with Next.js, Prisma, and PostgreSQL on Railway - Railway Help Station