supabase: Prisma unable to connect to Supabase database

Bug report

Describe the bug

Prisma npx commands and Prisma Studio are unable to connect to the Supabase database.

Running npx prisma migrate dev yields in the following error message:

> npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "db.xltfmrlaegzuuopvypxx.supabase.co:5432"

Error: P1001: Can't reach database server at `db.xltfmrlaegzuuopvypxx.supabase.co`:`5432`

Please make sure your database server is running at `db.xltfmrlaegzuuopvypxx.supabase.co`:`5432`.

I followed the advice at https://github.com/prisma/prisma/issues/13807 and I was indeed able to migrate an initial db after creating a temporary table.

But after running Prisma Studio I am unable to add any entries and once more unable to migrate a database:

image

Type: undefined
Message: 
Invalid `prisma.home.create()` invocation:


  Can't reach database server at `db.xltfmrlaegzuuopvypxx.supabase.co`:`5432`

Please make sure your database server is running at `db.xltfmrlaegzuuopvypxx.supabase.co`:`5432`.

Code: undefined

Query:
[object Object]

I made sure that my database password contains no special characters as #4161 discussed.

Using psql to connect to the data base shows no issues either and shows the appropriate tables:

> psql -h db.xltfmrlaegzuuopvypxx.supabase.co -p 5432 -U postgres -d postgres
Password for user postgres: 
psql (13.4, server 14.1)
WARNING: psql major version 13, server major version 14.
         Some psql features might not work.
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

postgres=> \c postgres
psql (13.4, server 14.1)
WARNING: psql major version 13, server major version 14.
         Some psql features might not work.
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
You are now connected to database "postgres" as user "postgres".
postgres=> \dt
               List of relations
 Schema |        Name        | Type  |  Owner   
--------+--------------------+-------+----------
 public | Home               | table | postgres
 public | _prisma_migrations | table | postgres
(2 rows)

image

System information

  • OS: Fedora 35
  • Browser: Brave v1.41.96
  • Version of Node.js: [16.16.0]

Additional context

Prisma schema:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Home {
  id          String   @id @default(cuid())
  image       String?
  title       String
  description String
  price       Float
  guests      Int
  beds        Int
  baths       Int
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 31 (5 by maintainers)

Most upvoted comments

Add connection timeout at the end of your DATABASE_URL.

?connect_timeout=300

My issue was solved by working from home hehe. When I had my issue I was trying to connect from a hotel lobby, but from my own apartment it seems to work fine.

Using psql to connect to the data base shows no issues either and shows the appropriate tables

I’m pretty sure this worked a few weeks ago.

Perhaps there was a change on the Prisma side? Did you also open this issue with the Prisma team? I’ll also give them a ping and see if they have any ideas

Thank you, that’s great to know 😄

You can probably close this issue then 🎉

Then it was probably a timeout error and adding a parameter connect_timeout to the connection string would have helped as well @kristianeboe with a higher than default value.

Also make sure that special characters are escaped in your password, otherwise it will break :

Character   Percent-Encoded
----------  -----------------
:          %3A
/          %2F
?          %3F
&          %26
=          %3D
@          %40
+          %2B
%          %25
#          %23

Yeah, we only do that if we need to - so just not doing that is not really an options unfortunately. I’ll check why and when we do the hammer method instead of nicely deleting the individual items we need to get rid of.

Hey @janpio, Wow, that would be awesome!

Running the prisma migrate dev command will drop the current database and remove all of the migrations, schemas, extensions, roles, and policies that are managed by Supabase. This could have serious consequences for our services.

It would be preferable if Prisma could avoid dropping the database when running the prisma migrate dev command.

However, there still may be conflicts with Prisma’s migrations that involve the installation of extensions, as we have our own process for installing extensions.

i am having the same issue using a hotel wifi, but it worked fine at home. if this info helps anyone 😃