0

I build a GraphQL API with Apollo and Prisma ORM which is connected to my hosted MySQL Database (The Database has already content in it). When I run it on my localhost everything works fine and I can query the Database with GraphQL statements. As soon as I deploy my node.js project to DigitalOcean (auto deployed with GitHub) it stops working and I get the following error:

{
  "errors": [
    {
      "message": "\nInvalid `prisma.content.findMany()` invocation in\n/workspace/src/schema.js:36:29\n\n  33 const resolvers = {\n  34   Query: {\n  35     memes: (parent, args) => {\n→ 36       return prisma.content.findMany(\n  error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.\n  -->  schema.prisma:7\n   | \n 6 |   provider = \"mysql\"\n 7 |   url      = env(\"DATABASE_URL\")\n   | \n\nValidation Error Count: 1",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "memes"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "clientVersion": "3.6.0",
          "stacktrace": [
            "Error: ",
            "Invalid `prisma.content.findMany()` invocation in",
            "/workspace/src/schema.js:36:29",
            "",
            "  33 const resolvers = {",
            "  34   Query: {",
            "  35     memes: (parent, args) => {",
            "→ 36       return prisma.content.findMany(",
            "  error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.",
            "  -->  schema.prisma:7",
            "   | ",
            " 6 |   provider = \"mysql\"",
            " 7 |   url      = env(\"DATABASE_URL\")",
            "   | ",
            "",
            "Validation Error Count: 1",
            "    at cb (/workspace/node_modules/@prisma/client/runtime/index.js:38689:17)",
            "    at processTicksAndRejections (internal/process/task_queues.js:97:5)"
          ]
        }
      }
    }
  ],
  "data": null
}

Here is my schema.prisma file:

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

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

The only thing that is different from the hosted project compared to the local project is that I put .env file and node_modules on the .gitignore file. So it seems like the project is accessing the wrong DATABASE_URL, but how should the hosted project know the DATABASE_URL in my .env file when the .env file is on .gitignore?

Here is what I do:

  1. Change the DATABASE_URL in my .env file to my local MySQL Database hosted on a docker container
  2. Run npx prisma migrate dev --preview-feature to generate the migration files
  3. Run git add .
  4. Run git commit -m "New Commit"
  5. Run DATABASE_URL=mysql://censored:censored@censored:3306/censored npx prisma migrate resolve --applied "my_migration_folder_name" --preview-feature which succeeds and tells me "Migration my_migration_folder_name marked as applied."
  6. Run git push

I can see that the Migration is successfully created on my MySQL Database but as soon as I run the app and try to query the database it gives me that error.

The code has to be correct because it is working on my localhost even when querying the hosted MySQL Database. I also double checked that the Model in the schema.prisma file is in sync with my hosted MySQL Database schema.

I'm running out of ideas on what I could try.

EDIT

I actually think it has something to do with the environment variables I set in the settings of my DigitalOcean application. Before it was set to:

  envs:
  - key: DATABASE_URL
    scope: RUN_AND_BUILD_TIME
    value: ${db.DATABASE_URL}

Now I set it to:

  envs:
  - key: DATABASE_URL
    scope: RUN_AND_BUILD_TIME
    value: mysql://censored:cesnored@censored:3306/censored

I thought that this will fix the problem but now it tells me that the connection fails because of wrong database credentials even though it is the right link with the right credentials.

2
  • Did you make sure the database url you're providing is accessible over the internet? You might accidentally be using a connection in your local network, or a connection that needs alll ip connecting to it to be whitelisted. Commented Dec 8, 2021 at 19:37
  • @TasinIshmam how do I check if my database URL is valid over the internet? It is not a http URL. Commented Dec 9, 2021 at 4:04

1 Answer 1

1

I fixed it by clicking "Force rebuild and deploy" on my digitalOcean app. enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.