How to run migrations exactly once with Turborepo connected to multiple projects on Vercel?
I have a Turborepo with "web" and "api" apps, and a "db" package that's used by both apps.
I also have 2 separate projects on Vercel, both are connected to this Turborepo. The "web" project is deploying the web app on "mysite.com", and the api project is deploying the api app on "api.mysite.com".
The "db" package has the following npm script:
When I push my code to Github, Vercel kicks-off the builds for both projects in parallel. Build could potentially be skipped if the code of the app didn't change.
I'd like to make sure to run the
db:migrate script before any of the apps' build starts.
But, if both projects build steps are run in parallel, I'm afraid that bunx drizzle-kit migrate could potentially run more than once, and if this happens, I wonder if it can cause any damage to the database.
What's the best way to deal with this?
Here is my turbo.json:
1 Reply
ambitious-aqua•14mo ago
Hmm, so if I understand correclty, inside the db package, you have the generated migrations folder, correct?