Next.js Discord

Discord Forum

How to Automatically Migrate Database on Vercel Deployment?

Answered
American black bear posted this in #help-forum
Open in Discord
Avatar
American black bearOP
I’m using Next.js hosted on Vercel for production and running locally for development. My PostgreSQL database is hosted on NeonDB for production and in a local Docker container for dev. I’m also using DrizzleORM for ORM and Drizzle Kit for migrations.

I want to automatically run database migrations when deploying to Vercel, similar to a pre-build hook.

Is this possible to do?
Answered by Yi Lon Ma
just update the build or start script of your application to run the migrations first and then the actual command after
View full answer

3 Replies

Avatar
just update the build or start script of your application to run the migrations first and then the actual command after
Answer
Avatar
"build":"drizzle-kit ... && next build"
Avatar
American black bearOP
that is genius, thank you!