Can't Reach Database
cyber-cute
FREEOP

a year ago

I have read the texts in the help section, but I am quite new to railway and I don't understand anything.

Solved$10 Bounty

54 Replies

cyber-cute
FREEOP

a year ago

a worker said to add 3 seconds in the forum, I added it, but the same problem still exists


cyber-cute
FREEOP

a year ago

im working with next.js and postgressql


a year ago

how exactly are you adding these 3 seconds?


cyber-cute
FREEOP

a year ago

so I didn't understand and chatgpt added something 3 seconds into lib/prisma.ts (and I guess it didn't work)


a year ago

can you undo what chatgpt suggested and show me your start command (or are you doing the migration in the pre-deploy command?)


cyber-cute
FREEOP

a year ago


import { PrismaClient } from '@prisma/client';

declare global {
  // eslint-disable-next-line no-var
  var prisma: PrismaClient | undefined;
}

let prisma: PrismaClient;

const connectWithRetry = async (client: PrismaClient, retries = 5, delay = 3000) => {
  for (let i = 0; i < retries; i++) {
    try {
      await client.$connect();
      console.log(':white_check_mark: Prisma: connected');
      return;
    } catch (error) {
      console.error(`❌ error (x${i + 1}):`, error);
      if (i < retries - 1) {
        await new Promise((res) => setTimeout(res, delay));
      } else {
        throw error;
      }
    }
  }
};

// Singleton ve retry birleştirildi
if (!globalThis.prisma) {
  const client = new PrismaClient();
  await connectWithRetry(client);
  globalThis.prisma = client;
}

prisma = globalThis.prisma;

export default prisma;

cyber-cute
FREEOP

a year ago

npm run migrate && npm start


cyber-cute
FREEOP

a year ago

alsi this is my pre deploy think


cyber-cute
FREEOP

a year ago

1369345039335034910


a year ago

can you show me this npm run migrate command?


a year ago

what does it reflect to in your package.json


a year ago

its blue, they have not yet saved the changes


a year ago

true


a year ago

btw I thought we didn't need to wait for the private network anymore


a year ago

I thought that was fixed


a year ago

🤔


a year ago

we dont, they likely read a very old thread


a year ago

yep


cyber-cute
FREEOP

a year ago

"name": "qrmenu",

"version": "0.1.1",

"private": true,

"scripts": {

"dev": "next dev",

"build": "next build --no-lint",

"start": "next start",

"postinstall": "npx prisma generate && npx prisma db push",

"lint": "next lint"

},

"prisma": {

"seed": "ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts"

},


cyber-cute
FREEOP

a year ago

uihh


cyber-cute
FREEOP

a year ago

I think I seemed to understand


cyber-cute
FREEOP

a year ago

migrate should be postinstall?


a year ago

no.


cyber-cute
FREEOP

a year ago

UH LOL


cyber-cute
FREEOP

a year ago

<:thinkies:1238577143466692739>


cyber-cute
FREEOP

a year ago

@Medim what the service settings tho


a year ago

try the public db url, I wanna see if it connects


cyber-cute
FREEOP

a year ago

same :cccccc


cyber-cute
FREEOP

a year ago

Am I missing something?


a year ago

link to project please



cyber-cute
FREEOP

a year ago

brody I'm not going to lie I'm used to doing everything with vercel with one click


a year ago

you are trying to reach the database over an http domain, let's go back to the private url.

unfortunately Railway the platform cannot help with incorrect implementation.


cyber-cute
FREEOP

a year ago

switchyard.proxy.rlwy.net:45368


cyber-cute
FREEOP

a year ago

so i should use this right?


a year ago

i'm wondering if it's because of his app being CSR


a year ago

that is the public TCP proxy, please go back to using the private url for the database connection


a year ago

yeah but CSR apps still won't talk to the database from the user's browser


cyber-cute
FREEOP

a year ago

this? postgresql://postgres:x@postgres.railway.internal:5432/railway


cyber-cute
FREEOP

a year ago

oke I'll try again


cyber-cute
FREEOP

a year ago

Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error

PrismaClientInitializationError:

Invalid prisma.appSettings.findUnique() invocation:

Can't reach database server at postgres.railway.internal:5432

Please make sure your database server is running at postgres.railway.internal:5432.

at zn.handleRequestError (/app/node_modules/.prisma/client/runtime/library.js:124:7759)

at zn.handleAndLogRequestError (/app/node_modules/.prisma/client/runtime/library.js:124:6784)

at zn.request (/app/node_modules/.prisma/client/runtime/library.js:124:6491)

at async l (/app/node_modules/.prisma/client/runtime/library.js:133:9778)

at async l (/app/.next/server/app/page.js:1:1253)

Export encountered an error on /page: /, exiting the build.


a year ago

the private network is not available during build, you will need to switch to SSR during runtime instead of SSG during build, or temporarily switch to the public network just for build time.

I'll let the community help with the implementation details.


cyber-cute
FREEOP

a year ago

uhmm


cyber-cute
FREEOP

a year ago

i dont understand really


cyber-cute
FREEOP

a year ago

oke sir thx


cyber-cute
FREEOP

a year ago

❤️


a year ago

You got two approaches to this issue:

  • Switching to SSR (easier one but depends on your nextjs project)
  • Conditionally switch between private (on runtime) and public (on build) db url, you can identify in which step nextjs is with the NEXT_PHASE env var

cyber-cute
FREEOP

a year ago

frankly, the project is not mine, I was just helping someone or he will try to host the next.js project from cpanel


cyber-cute
FREEOP

a year ago

uhh ok I can try that


a year ago

The easier approach is to switch to SSR, that's a one liner depending on the project


cyber-cute
FREEOP

a year ago

I'm really confused lol I need a drink of water.


cyber-cute
FREEOP

a year ago

thx medim


a year ago

No worries, sorry I couldn't be more helpful! this is more of a code issue and I have some skill issues with nextjs <:kekw:788259314607325204>


a year ago

!s


Status changed to Solved medim about 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...