Need help debug deployment of the staging db

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.

Finally resolved it after hours!

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:

  1. Update the correct DATABASE_URL, DIRECT_URL for staging
  2. add a new build command in script: “vercel-build”: “prisma generate && prisma migrate deploy && next build”, and run it in vercel build
1 Like

Thanks for coming back with your solution, @qm994! :smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.