How to use Prisma 2 CLI on Heroku

佐手、 提交于 2021-02-10 14:44:55

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/65165511/how-to-use-prisma-2-cli-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!