database connection stopped working

farvaPRO

24 days ago

i dont need pointing to a guid, i need help fixing. Something changed and my deployments are not working anymore, the db connection from the nextjs app to postgress is failing at build , example:

Datasource "db": PostgreSQL database "railway", schema "public" at "autorack.proxy.rlwy.net:33356"

May 20 08:28:27

May 20 08:28:27

Error: P1001: Can't reach database server at autorack.proxy.rlwy.net:`33356` Please make sure your database server is running at autorack.proxy.rlwy.net:`33356`.

May 20 08:28:27

✕ [stage-0 8/10] RUN --mount=type=cache,id=s/1b58e6f1-0237-4d5e-a045-adf18eb78cf4-next/cache,target=/app/.next/cache --mount=type=cache,id=s/1b58e6f1-0237-4d5e-a045-adf18eb78cf4-node_modules/cache,target=/app/node_modules/.cache prisma generate && prisma migrate deploy && next build

process "/bin/bash -ol pipefail -c prisma generate && prisma migrate deploy && next build" did not complete successfully: exit code: 1

May 20 08:28:28

Dockerfile:24

May 20 08:28:28

-------------------

May 20 08:28:28

22 | # build phase

May 20 08:28:28

23 | COPY . /app/.

May 20 08:28:28

24 | >>> RUN --mount=type=cache,id=s/1b58e6f1-0237-4d5e-a045-adf18eb78cf4-next/cache,target=/app/.next/cache --mount=type=cache,id=s/1b58e6f1-0237-4d5e-a045-adf18eb78cf4-node_modules/cache,target=/app/node_modules/.cache prisma generate && prisma migrate deploy && next build

May 20 08:28:28

25 |

May 20 08:28:28

26 |

May 20 08:28:28

-------------------

May 20 08:28:28

ERROR: failed to solve: process "/bin/bash -ol pipefail -c prisma generate && prisma migrate deploy && next build" did not complete successfully: exit code: 1

May 20 08:28:28

Error: Docker build failed

$10 Bounty

2 Replies

farvaPRO

24 days ago

postgres shows spinning database connection

Attachments


23 days ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 23 days ago


seiyialHOBBY

23 days ago

Hi farva! I faced this before and was stuck for a pretty long time, but I have the solution now!

The problem:
At the build phase, you do NOT have access to your internal network.

There was a time where railway built an experimental "Builder V2" which allowed it, but then it seems to be deprecated: https://railway.com/changelog/2025-05-02-great-metal-migration#builder-v2-deprecation

But that's not a problem! Here's how I do it for Prisma with NextJS.

Option 1 (recommended)

Build command: prisma generate && next build
Start command: prisma migrate deploy && next start

This works because:-

  • prisma generate does not need network access, and therefore can be done at the build phase.

  • prisma migrate deploy needs network access to your database. You only have access to the database via the internal network at the start phase, so I run it here. prisma migrate deploy doesn't do anything if your database is up to date, and it only slows down your restarts by a second or so, so I think this is okay.

  • prisma migrate deploy does not actually modify your source code (unlike prisma migrate dev), and that's why it can be run after deployment.

Option 2 (NOT recommended)

Use ${{Postgres.DATABASE_PUBLIC_URL}} instead of ${{Postgres.DATABASE_URL}} as the DATABASE_URL environment variable for your app. ${{Postgres.DATABASE_PUBLIC_URL}} points to the database publicly through the internet, and therefore works during the build phase without internal network access.

I've used it before, but I don't believe it's a good idea because:-

  • Additional routing through the internet may be needed (potentially increased ping in every database-accessing request)

  • It's less secure because your application runtime now has an internationally accessible authenticated DATABASE_URL to your database.