prisma / nuxt-prisma

Prisma ORM integration for Nuxt
https://www.prisma.io/docs/orm/more/help-and-troubleshooting/help-articles/prisma-nuxt-module
29 stars 1 forks source link

Gracefully handle MongoDB migration #11

Open KyleSmith0905 opened 1 week ago

KyleSmith0905 commented 1 week ago

Description

When selecting yes on "Do you want to migrate database changes to your database?" my CLI would spit out an error. (edit: I read the message of course, but it probably should not give an error if I was prompted to do something).

Idk if this is a bigger error but right after I get a message saying "Failed to install Prisma Client", I assume they're linked.

Reproduction

https://github.com/KyleSmith0905/mre--prisma-nuxt

Or create a new Nuxt project with "pnpm dlx nuxi@latest init " and add prisma's packages and modules to it

CLI

√ Do you want to migrate database changes to your database? ... yes
Migrating database schema...                                                                                                                                                                        7:20:57 PM  

 ERROR  ✘ Failed to run Prisma migration.                                                                                                                                                           7:20:58 PM  

Command failed with exit code 1: npx prisma migrate dev --name init                                                                                                                                 7:20:58 PM  
Error: The "mongodb" provider is not supported with this command. For more info see https://www.prisma.io/docs/concepts/database-connectors/mongodb
   0: schema_core::state::DevDiagnostic
             at schema-engine\core\src\state.rs:276

Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MongoDB database "db" at "cluster.nzjgwap.mongodb.net"

  Error: The "mongodb" provider is not supported with this command. For more info see https://www.prisma.io/docs/concepts/database-connectors/mongodb
  0: schema_core::state::DevDiagnostic
  at schema-engine\core\src\state.rs:276

  Environment variables loaded from .env
  Prisma schema loaded from prisma\schema.prisma
  Datasource "db": MongoDB database "db" at "cluster.nzjgwap.mongodb.net"

  at makeError (/C:/Users/ceohi/OneDrive/Documents/projects/mre--prisma-nuxt/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/error.js:60:11)
  at handlePromise (/C:/Users/ceohi/OneDrive/Documents/projects/mre--prisma-nuxt/node_modules/.pnpm/execa@8.0.1/node_modules/execa/index.js:124:26)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async runMigration (/C:/Users/ceohi/OneDrive/Documents/projects/mre--prisma-nuxt/node_modules/.pnpm/@prisma+nuxt@0.0.30_nuxt@3.12.2_prisma@5.15.1_vite@5.3.1/node_modules/@prisma/nuxt/dist/module.mjs:235:5)
  at async migrateAndFormatSchema (/C:/Users/ceohi/OneDrive/Documents/projects/mre--prisma-nuxt/node_modules/.pnpm/@prisma+nuxt@0.0.30_nuxt@3.12.2_prisma@5.15.1_vite@5.3.1/node_modules/@prisma/nuxt/dist/module.mjs:406:9)
  at async prismaMigrateWorkflow (/C:/Users/ceohi/OneDrive/Documents/projects/mre--prisma-nuxt/node_modules/.pnpm/@prisma+nuxt@0.0.30_nuxt@3.12.2_prisma@5.15.1_vite@5.3.1/node_modules/@prisma/nuxt/dist/module.mjs:421:9)
  at async setup (/C:/Users/ceohi/OneDrive/Documents/projects/mre--prisma-nuxt/node_modules/.pnpm/@prisma+nuxt@0.0.30_nuxt@3.12.2_prisma@5.15.1_vite@5.3.1/node_modules/@prisma/nuxt/dist/module.mjs:469:7)     
  at async normalizedModule (/C:/Users/ceohi/OneDrive/Documents/projects/mre--prisma-nuxt/node_modules/.pnpm/@nuxt+kit@3.12.2_magicast@0.3.4/node_modules/@nuxt/kit/dist/index.mjs:2127:17)
  at async installModule (/C:/Users/ceohi/OneDrive/Documents/projects/mre--prisma-nuxt/node_modules/.pnpm/@nuxt+kit@3.12.2_magicast@0.3.4/node_modules/@nuxt/kit/dist/index.mjs:2469:95)
  at async initNuxt (/C:/Users/ceohi/OneDrive/Documents/projects/mre--prisma-nuxt/node_modules/.pnpm/nuxt@3.12.2_@opentelemetry+api@1.8.0_@unocss+reset@0.61.0_floating-vue@5.2.2_unocss@0.61.0_vite@5.3.1/node_modules/nuxt/dist/index.mjs:4395:5)
                                                                                                                                                                                                    7:20:58 PM  
Hint: You can manually run migrations by executing npx prisma migrate dev or visit the Prisma Migrate docs for more info:
https://pris.ly/nuxt/migrate. Or if you have pre-existing data on your database, you have to introspect it. Learn more in our docs:
https://pris.ly/nuxt/dbpull.

Formatting Prisma schema...                                                                                                                                                                         7:20:58 PM  

Generating Prisma client...                                                                                                                                                                         7:21:00 PM

 ERROR  ✘ Failed to install Prisma Client.                                                                                                                                                          7:21:14 PM  

                                                                                                                                                                                                    7:21:16 PM
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
ankur-arch commented 1 week ago

Hey there @KyleSmith0905 👋, thanks for reproducing the issue 😄!

(edit: I read the message of course, but it probably should not give an error if I was prompted to do something)

Migration prompts can sometimes fail. If they do, we provide steps to handle the error. Could you let me know what you were expecting to happen?

ERROR ✘ Failed to install Prisma Client.

This error seems to occur when using pnpm, but the module should work as expected. The error disappears when I run pnpm i @prisma/client.

I'll look into this further.

KyleSmith0905 commented 1 week ago

I would expect either one of these two:

  1. Not prompt of migration if it's not possible.
  2. Handle the CLI output gracefully by printing "MongoDB provider couldn't be migrated" instead of the errorz

You'll probably have better intuition, on what reads the best. 👍

Despite seeing why the error was caused, I had inferred something else was wrong (since I got a whole stack trace).

ankur-arch commented 1 week ago

Thanks again for elaborating!

We'll possibly keep the verbose log turned off by default and add a key in the config to enable it for further debugging.