prisma1 icon indicating copy to clipboard operation
prisma1 copied to clipboard

Error relation "default$default.user" does not exist. Existing pgsql db

Open SawasReaper opened this issue 5 years ago • 10 comments

Hi, I try to run prisma on my existing postgres db, but after few hours I'm in same buggy spot. I have public schema in db but prisma try to resolve queries on default$default.

My docker-compose.yml

version: "3.6"

services:
  offhub_pgsql:
    image: postgres:9.6.6-alpine
    volumes:
      - ./postgres_data:/var/lib/postgresql/data/
    environment: 
      POSTGRES_USER: offhub
      POSTGRES_PASSWORD: offhub
      POSTGRES_DB: offhub
    ports:
      - 5432:5432

  offhub_backend:
    build: .
    command: npm run dev
    volumes:
      - ./:/app
      - /app/node_modules
    env_file:
      - .env
    depends_on:
      - offhub_pgsql
    ports:
      - 9229:9229

  offhub_nginx:
    build:
      dockerfile: Dockerfile
      context: nginx/
    ports:
      - 3030:80
    depends_on:
      - offhub_backend

  prisma:
    image: prismagraphql/prisma:1.29.2
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        managementApiSecret: my-secret
        databases:
          default:
            connector: postgres
            host: host.docker.internal 
            database: offhub
            user: offhub
            password: offhub
            rawAccess: true
            port: '5432'
            migrations: false

volumes:
  postgres:

My prisma.yml Btw I think there is another issue. I can't do prisma deploy if it's not on localhost http://localhost:4466

endpoint: http://host.docker.internal:4466
datamodel: datamodel.prisma

generate:
  - generator: typescript-client
    output: ./generated/prisma-client/

I've also tried just with simple model from db:

type User @pgTable(name: "user") {
  id: UUID! @unique
  name: String
}

and behaviour is still same.

I've tried quering by playground and with express by adding:

import { prisma } from "../../prisma/generated/prisma-client"

// A `main` function so that we can use async/await
async function main() {
    // Create a new user called `Alice`
    const newUser = await prisma.createUser({ name: "Alice" })
    console.log(`Created new user: ${newUser.name} (ID: ${newUser.id})`)

    // Read all users from the database and print them to the console
    const allUsers = await prisma.users()
    console.log(allUsers)
}

main().catch(e => console.error(e))

Postgres logs: Screenshot 2019-03-29 at 13 59 21

Prisma logs: Screenshot 2019-03-29 at 13 59 52

Express logs: Screenshot 2019-03-29 at 14 00 11

When I've tried this config on empty db with migrations:true prisma created default$default schema and everything seem to work fine but it isn't behaviour that I'm looking for.

Versions (please complete the following information):

  • Connector: Postgres
  • Prisma Server: 1.29.2
  • prisma CLI: prisma/1.29.1 (darwin-x64) node-v10.15.1
  • OS: OS X High Sierra
  • other dependencies: prisma-client

thx for help 😄

SawasReaper avatar Mar 29 '19 13:03 SawasReaper

@SawasReaper : Thanks for raising this issue with a reproduction, I was able to reproduce it. This is happening because of this bug in Prisma CLI: https://github.com/prisma/prisma/issues/4282 which makes Prisma server go to an incorrect code path.

A fix will be required in both CLI and server side. However, a workaround is to add the schema name to docker-compose.yml file manually and then run docker-compose-up -d followed by prisma deploy.

Please let me know if this workaround works for you.

divyenduz avatar Mar 29 '19 17:03 divyenduz

P.S. here is my reproduction for this issue: https://github.com/divyenduz/prisma-4278

divyenduz avatar Mar 29 '19 17:03 divyenduz

@divyenduz thanks for quick answer. Adding schema: public worked for me perfectly. To be honest I've tried it before but I've had some issue with prisma deploy. Now works perfectly.

Screenshot 2019-03-29 at 19 39 20 Screenshot 2019-03-29 at 19 41 02

Should I create another issue for bug I mentioned before? It's related with prisma deploy on endpoint: http://host.docker.internal:4466

Screenshot 2019-03-29 at 19 42 26

When I go with endpoint: http://localhost:4466 everything is fine with prisma deploy but dockerized express rise issue on prisma generated endpoint and I need to replace it manually with endpoint: http://host.docker.internal:4466 in index.ts

Screenshot 2019-03-29 at 19 45 01

SawasReaper avatar Mar 29 '19 18:03 SawasReaper

Thanks for letting us know, the issue regarding authentication is actively being discussed here: https://github.com/prisma/prisma/issues/4215

I can imaging why this is failing, we need to mark host.docker.internal explicitly as localhost.

divyenduz avatar Mar 29 '19 19:03 divyenduz

Hmm, I think I found another one. It's related with schema: public. When I added it to my docker-compose.yml and went with prisma deploy it crashes on my real pgsql database and nth wasn't added to project/migration tables in managment schema.

Screenshot 2019-03-31 at 00 23 32

But when I comment schema: public and run prisma deploy it's 👌 and my model is added to migration table in managment schema.

Screenshot 2019-03-31 at 00 36 10 Screenshot 2019-03-31 at 00 26 30

Then I uncommented my schema: public and restarted docker container and it's fine.

Screenshot 2019-03-31 at 00 29 44

Full log from debug:

Screenshot 2019-03-31 at 00 31 12

If you need some more info please tell me. I'm happy to help.

SawasReaper avatar Mar 30 '19 23:03 SawasReaper

@SawasReaper It should be schema:pubic right? as schema is the key that Prisma reads to choose the schema name which is public.

divyenduz avatar Mar 31 '19 11:03 divyenduz

Yes, of course. I've done it like this schema: public.

SawasReaper avatar Mar 31 '19 12:03 SawasReaper

@divyenduz Should I open another issue for that?

SawasReaper avatar Mar 31 '19 18:03 SawasReaper

@SawasReaper : Thank you, please create another issue with a minimal reproduction 🙏 That would help us tackle them separately.

divyenduz avatar Mar 31 '19 18:03 divyenduz

I'm using schema:public and it does not seem to have any effect, I'm still getting:

The provided schema "default$default" does not exist. The following are available: public, management

serranoarevalo avatar Apr 05 '19 00:04 serranoarevalo