Warm tip: This article is reproduced from serverfault.com, please click

How to use Prisma 2 CLI on Heroku

发布于 2020-12-06 06:57:57

I have deployed NestJs application on Heroku which uses Prisma 2, but when I run the command npx prisma --version on heroku bash I get Prisma CLI version: prisma/1.34.10 (linux-x64) node-v14.15.0 but I have installed prisma 2.11.0, I want to use Prisma 2 cli to introspect my existing database, and run prisma generate.

Questioner
don
Viewed
0
don 2020-12-09 17:49:02

I managed to introspect my existing database and run prisma generate by adding heroku-postbuild command on my package.json in scripts section as show below:

{
   "scripts": {
      "heroku-postbuild": "prisma introspect && prisma generate"
   }
}

Now when I push to heroku the heroku-postbuild command will be executed.

Note: By default, Heroku after installing all dependencies listed in package.json under dependencies and devDependencies will strip out (Pruning devDependencies) the packages declared under devDependencies before deploying the application.

heroku-postbuild runs after Heroku installs dependencies, but before Heroku prunes and caches dependencies. Thus why the specified prisma introspect && prisma generate will use the prisma cli specified on package.json.

Note: To skip the pruning step of devDependencies set NPM_CONFIG_PRODUCTION to false as shown below, so that we can access packages declared under devDependencies at runtime:

heroku config:set NPM_CONFIG_PRODUCTION=false

After setting NPM_CONFIG_PRODUCTION to false now if we run npx prisma --version we will get the installed version from package.json

For more information please visit : https://devcenter.heroku.com/articles/nodejs-support#build-behavior