I have setup a sepratae staging db in supabase and connect to the vercel and put the separate DATABASE_URL in env variables for both production and preview.
The preview DATABASE_URL only for the staging branch of Git Repo.
My expectation is whenever i checkout a feature branch against the staging branch, there preview app will use the staging database instead of the production one.
Current behavior: when i open the Pull Request against the staging, there is always a runtime log error said: DATABASE_URL not found. See the attachment for exact error.
Here are the root cause and fix incase someone else hsa this in the future:
I was using supabase psql pgbouncer connection and using the directUrl in prisma schema for connection and migration but my env DATABASE_URl used the normal url provided by Supabase.
I fix this by:
Update the correct DATABASE_URL, DIRECT_URL for staging
add a new build command in script: “vercel-build”: “prisma generate && prisma migrate deploy && next build”, and run it in vercel build