Setting up automated deploys for GitHub to Vercel to Neon
I setup a production environment in my app and followed the instructions to use the Neon integration within Vercel. Everything was working fine until my dev build required a Prisma migration. I ran the migration locally and everything is working in the dev environment, but when I attempted to run the new code in a preview (and in the main build) the app breaks because it appears that the migration does not apply to remote branches.
I had an issue with migrations in the past, due to missing environment variables, so I created a local script to initiate a migration in my dev environment. Thus the migration runs and updates my dev instance of Neon without issue.
I have this script defined in my
package.json file as, "migrate-dev": "node migrate-dev.mjs", in my scripts. In my local terminal I run npm run migrate-dev to manually initiate a migration.
The problem I'm facing is how do I take that migration and apply it to main (production) or to any of my preview deploys from Vercel to Neon?
In my Vercel setup I followed instructions I saw online to add a custom build command, so my Vercel project runs npx prisma generate && npm run build at build. Everything seemed to be working, but as I mentioned apparently a migration is not being initiated at build. I'd appreciate any help I can get to help me fix my deploy process. Thanks!4 Replies
rival-black•16mo ago
@Mahmoud or @Rishi Raj Jain can you take a look here
like-goldOP•16mo ago
I think I figured it out. I added migrate to my build command.
npx prisma generate && npx prisma migrate deploy && npm run build
If you have any recommendations for improvement, I'm all ears. I appreciate your help!
The first time I deployed (with a change to the Prisma schema) the deploy built without a hitch. I initiated a new deploy and it's failing during the build process—something I had seen locally that caused me to create a migration script that I manually run in dev.
Here is the error log:
rival-black•16mo ago
The error says your environment variable is not available
like-goldOP•16mo ago
Yes I understood that part. I'm not sure what happened but when I checked back in later my deploy had rebuilt and was working. Maybe it was a Vercel thing. 🤷♂️ Thanks.