Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Prisma doesn't execute mutations on tables in public schema of existing PostgreSQL database #2846

Closed
Chittatosh opened this issue Aug 1, 2018 · 2 comments · Fixed by #2888
Labels
bug/1-repro-available A reproduction exists and needs to be confirmed.

Comments

@Chittatosh
Copy link

Chittatosh commented Aug 1, 2018

Describe the bug
A clear and concise description of what the bug is.

When schema: public option is provided in docker-compose.yml, Prisma successfully executes queries on tables in public schema of existing PostgreSQL database. But during mutations, Prisma looks for the table in default$default schema and then PostgreSQL throws the following error since the table exists in public schema and not default$default schema.

prisma_1  | org.postgresql.util.PSQLException: ERROR: relation "default$default.manager_keyword" does not exist

To Reproduce
Steps to reproduce the behavior:

  1. Create files

prisma init

Selecting existing PostgreSQL database during prisma init creates prisma.yml, datamodel.graphql and docker-compose.yml.

prisma.yml:

endpoint: http://localhost:4466
datamodel: datamodel.graphql

datamodel.graphql:

type Manager_keyword @pgTable(name: "manager_keyword") {
  id: Int! @unique
  geo: String
  keyword: String
}

docker-compose.yml:

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.14
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        databases:
          default:
            connector: postgres
            host: ***.rds.amazonaws.com
            port: '5432'
            database: ***
            schema: public
            user: ***
            password: ***
            migrations: false
  1. Deploy

docker-compose up (-d option omitted to view logs)

In another terminal,

prisma deploy

  1. Query

Executing this query in graphql playground (localhost:4466)

{
  manager_keywords {
    id
    geo
    keyword
  }
}

gives this result:

{
  "data": {
    "manager_keywords": [
      {
        "id": 1,
        "geo": "DE",
        "keyword": "kw1"
      },
      {
        "id": 2,
        "geo": "UK",
        "keyword": "kw2"
      }
    ]
  }
}

which is expected and matches the result from psql:

SELECT * FROM manager_keyword;
 id | keyword | geo
----+---------+-----
  1 | kw1     | DE
  2 | kw2     | UK
(2 rows)

This shows that prisma is able to read from the public schema of PostgreSQL.

  1. Error during mutations

Executing the create mutation

mutation {
  createManager_keyword(data: { geo: "FR", keyword: "kw3" }) {
    id
    geo
    keyword
  }
}

results in this error in graphql playground:

{
  "data": null,
  "errors": [
    {
      "message": "Whoops. Looks like an internal server error. Search your server logs for request ID: local:api:cjkb3vjy3000b0856unkcajlv",
      "path": [
        "createManager_keyword"
      ],
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "requestId": "local:api:cjkb3vjy3000b0856unkcajlv"
    }
  ]
}

and a corresponding error from PostgreSQL in docker-compose up:

prisma_1  | {"key":"error/unhandled","requestId":"local:api:cjkb3vjy3000b0856unkcajlv","clientId":"default$default","payload":{"exception":"org.postgresql.util.PSQLException: ERROR: relation \"default$default.manager_keyword\" does not exist\n  Position: 13","query":"mutation {\n  createManager_keyword(data: {geo: \"UK\", keyword: \"kw3\"}) {\n    id\n    geo\n    keyword\n  }\n}\n","variables":"{}","code":"0","stack_trace":"org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)\\n org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2178)\\n org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:306)\\n org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)\\n org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)\\n org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155)\\n org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:144)\\n com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)\\n com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)\\n com.prisma.api.connector.jdbc.database.BuilderBase.$anonfun$insertReturningGeneratedKeysToDBIO$1(BuilderBase.scala:64)\\n com.prisma.api.connector.jdbc.database.BuilderBase.$anonfun$jooqToDBIO$1(BuilderBase.scala:87)\\n slick.jdbc.SimpleJdbcAction.run(StreamingInvokerAction.scala:70)\\n slick.jdbc.SimpleJdbcAction.run(StreamingInvokerAction.scala:69)\\n slick.basic.BasicBackend$DatabaseDef$$anon$2.liftedTree1$1(BasicBackend.scala:275)\\n slick.basic.BasicBackend$DatabaseDef$$anon$2.run(BasicBackend.scala:275)\\n java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\\n java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\\n java.lang.Thread.run(Thread.java:748)","message":"ERROR: relation \"default$default.manager_keyword\" does not exist\n  Position: 13"}}
prisma_1  | [Bugsnag - local / testing] Error report: com.bugsnag.Report@89ae9a8
prisma_1  | org.postgresql.util.PSQLException: ERROR: relation "default$default.manager_keyword" does not exist

This error is thrown during update and delete mutations too.

It seems that prisma looks for the table in default$default schema during mutations and public schema during queries.

Expected behavior
A clear and concise description of what you expected to happen.

Mutations should be executed on a given table in public schema instead of default$default schema when schema: public option is provided in docker-compose.yml.

Screenshots
If applicable, add screenshots to help explain your problem.

Versions (please complete the following information):

  • OS: Ubuntu 18.04 LTS
  • prisma cli: prisma/1.14.0-Beta (linux-x64) node-v8.11.3
  • docker-compose: docker-compose version 1.22.0, build f46880fe

Additional context
Add any other context about the problem here.

  1. Other logs related to default$default schema from docker-compose up:
prisma_1  | [Metrics] No Prisma Cloud secret is set. Metrics collection is disabled.
prisma_1  | [Debug] Initializing deployment worker for default$default
prisma_1  | [Debug] Scheduling deployment for project default$default
prisma_1  | Warning: Management API authentication is disabled. To protect your management server you should provide one (not both) of the environment variables 'CLUSTER_PUBLIC_KEY' (asymmetric, deprecated soon) or 'PRISMA_MANAGEMENT_API_JWT_SECRET' (symmetric JWT).
prisma_1  | [Debug] Applied migration for project default$default
  1. The create mutation works if a new manager_keyword table is created in default$default schema. But this is not helpful since queries are executed on a table in public schema and mutations are executed on a different table in default$default schema

  2. If schema: public option is not provided in docker-compose.yml, then all queries and mutations work as expected in default$default schema.

@marktani
Copy link
Contributor

marktani commented Aug 3, 2018

Related to #2866.

@mavilein
Copy link
Member

mavilein commented Aug 8, 2018

Thanks for reporting! I implemented a bugfix and just triggered a new release/
The release is 1.13.7 and will be availabel in a few minutes: https://github.com/prismagraphql/prisma/releases/tag/1.13.7

@pantharshit00 pantharshit00 added the bug/1-repro-available A reproduction exists and needs to be confirmed. label Jan 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/1-repro-available A reproduction exists and needs to be confirmed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants