Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma Postgres stopped working out of sudden, saying database string is invalid #22992

Closed
franva opened this issue Feb 7, 2024 · 0 comments
Closed
Labels
kind/bug A reported bug.

Comments

@franva
Copy link

franva commented Feb 7, 2024

Bug description

I was debugging my Next.js project with Prisma as my ORM. Everything was working fine. I logged into the dashboard page which lists all products from the Vercel Postgres database by using Prisma client.

Out of sudden, Prisma stopped working and no data can be fetched, basically any operations via Prisma error out. Here is an error example:

Invalid `prisma.artworks.findMany()` invocation:

The provided database string is invalid. The provided arguments are not supported in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.

I have not changed anything in the .env or .env.local files, I did not even open those 2 files. So I opened the Vercel website, and copied the database connection strings again and put it into these 2 environment config files,

POSTGRES_URL="postgres://default:<mypassword>@ep-divine-smoke-00439065-pooler.us-east-1.postgres.vercel-storage.com:5432/verceldb"
POSTGRES_PRISMA_URL="postgres://default:<mypassword>@ep-divine-smoke-00439065-pooler.us-east-1.postgres.vercel-storage.com:5432/verceldb?pgbouncer=true&connect_timeout=15"
POSTGRES_URL_NON_POOLING="postgres://default:<mypassword>@ep-divine-smoke-00439065.us-east-1.postgres.vercel-storage.com:5432/verceldb"
POSTGRES_USER="default"
POSTGRES_HOST="ep-divine-smoke-00439065-pooler.us-east-1.postgres.vercel-storage.com"
POSTGRES_PASSWORD="<mypassword>"
POSTGRES_DATABASE="verceldb"

(I replaced the real password with in this post, but the real env files have the correct password which I copied from Vercel without any change).

Also copied the code for use in Prisma's schema file like below:


datasource db {    
  provider = "postgresql"    
  url = env("POSTGRES_PRISMA_URL") // uses connection pooling    
  directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection    
}

Also I just notice that I can pull my db schema from the Vercel PostgreSql database, this means the database connection string actually works. The issue could come from Prisma.

image

Also, I am able to launch the Prisma Studio and see all the data. So this is for sure the issue from PrismaClient.

How to reproduce

  1. create a next project
  2. create a project on Vercel which has a storage with Postgres
  3. copy the code snippet from .env.local tab in Storage section on the Vercel platform
  4. create the .env file and pasted in the code snippet
  5. Also copy the code snippet from Prisma tab on Vercel's storage section and pasted in schema.prisma
  6. Pull and generate the code for the Database in the next.js project, npx prisma db pull and npx prisma generate,
  7. Run any operations with the PrismaClient to see the error

Expected behavior

I expect it to work as previously.

Prisma information

// Add your schema.prisma
datasource db {
  provider  = "postgresql"
  url       = env("POSTGRES_PRISMA_URL")
  directUrl = env("POSTGRES_URL_NON_POOLING")
}

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

model likes {
  userid    String    @db.Uuid
  artworkid String    @db.Uuid
  likeddate DateTime? @default(now()) @db.Timestamp(6)
  artworks  artworks  @relation(fields: [artworkid], references: [id], onDelete: NoAction, onUpdate: NoAction)
  users     users     @relation(fields: [userid], references: [id], onDelete: NoAction, onUpdate: NoAction)

  @@id([userid, artworkid])
}

...... and other models
// Add your code using Prisma Client
import { PrismaClient, artworkimages, artworks, artworktags, tags, users } from '@prisma/client'
const prisma = new PrismaClient();

export async function getAllUsers(): Promise<users[]> {
  try {
    const activeUsers = await prisma.users.findMany({
      where: { isactive: true }
    });

    return activeUsers;
  } catch (error) {
    console.error('Failed to fetch user:', error);
    throw new Error('Failed to fetch user.');
  }
}

Environment & setup

  • OS: Windows 11 Pro
  • Database: PostgreSQL
  • Node.js version: v20.9.0

Prisma Version

"@prisma/client": "^5.9.1",
@franva franva added the kind/bug A reported bug. label Feb 7, 2024
@prisma prisma locked and limited conversation to collaborators Feb 7, 2024
@laplab laplab converted this issue into discussion #23000 Feb 7, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

1 participant