prisma / docs

📚 Prisma Documentation
https://www.prisma.io/docs
Apache License 2.0
983 stars 777 forks source link

Vercel deployment behaves suboptimal when deploying multiple functions #5056

Open janpio opened 3 years ago

janpio commented 3 years ago

In our Vercel deployment guide we recommend putting prisma generate in a postinstall script, and any Migrations via prisma migrate deploy into the vercel-build script:

https://www.prisma.io/docs/guides/deployment/deployment-guides/deploying-to-vercel#vercel-specific-notes

It seems that when your application is deploying multiple functions, some possibly that do not use Prisma, both these scripts are executed for each function instead of once per deployment.

The theory is that Vercel installs dependencies for each serverless function individually instead of just once (to optimize the deployment size of each serverless function), and also executes these scripts each time.

(Reported via private Slack Direct Message)

On the other hand: Both prisma migrate and prisma generate are idempotent usually, so there is no real negative effect of running these multiple times. We should still understand.

janpio commented 3 years ago

Most of this is observation and guesses for now, so it would be good to reproduce this with a repository that includes 2 functions, one using Prisma and one not using Prisma. The generate and migrate deploy commands can in theory be replaced with simple outputs of a string. This should be enough to confirm the behavior on Vercel.

tomhoule commented 3 years ago

Note: this might be a docs problem.

grokpot commented 11 months ago

@janpio The docs page you've linked no longer mentions anything about migrate, I think it should (currently working on that and a bit confused). Things which aren't clear to me, which you might want to make clear:

  1. Should I run migrate or generate first?
  2. I found a SO Post mentioning vercel-build, but I think that script is now just build
  3. Should I run prisma migrate deploy in build or in postinstall ?

What's working for me (Nuxt + Prisma + Vercel):

  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare && prisma migrate deploy && prisma generate"
  },

Relevant: