When to run migration in production with Turborepo?
Hey there 👋 in the official Prisma-Turborepo guide (https://www.prisma.io/docs/guides/turborepo#1-create-your-monorepo-using-turborepo), it says to "ensure that db:generate is always executed before running dev or build. Additionally, make sure both db:deploy and db:generate are executed before db:build." Yet, in the example code given, we see only
db:generate
as a dependency of build.
If db:deploy
(prisma migrate deploy
) needs to run prior to the build command, do we run this explicitly with Turbo (specified in the config)?
...or do we run this independently using our build environment like turbo db:deploy && turbo build --filter=api
? Also, I am assuming the deploy script always go before the generate script, but I am unsure how to order these in the execution chain, or if that's even possible. I believe these scripts might execute simultaneously?2 Replies
You decided to hold for human wisdom. We'll chime in soon! Meanwhile,
#ask-ai
is there if you need a quick second opinion.Hey!
If your build or runtime requires the database schema to be up-to-date, then you should add
^db:deploy
as a dependency as well, similar to "^db:generate"
.
The main requirement is that both commands are run before build if your build depends on the latest schema and generated client.
As you mentioned, you can run them explicitly in your build environment to guarantee order like: turbo run db:deploy && turbo run db:generate && turbo run build --filter=api
This ensures that migrations are applied, then the client is generated, then the build runs.