N
Neon5d ago
fair-rose

Branch not created per PR (deployment) on Vercel

I have a Next.js project deployed on Vercel and Neon connected to the project via Vercel Marketplace. I have the project configured with the following settings: Environments Choose which environments of the project to make this database available to. ​[x] Development [x]​ Preview ​[x] Production Resource is Required To Be In An Active State Before Deployment [x] Required Create database branch for deployment ​[x] Preview ​[ ] Production Issue: when I push a new PR to be built and deployed on Vercel, then it is deployed as a Preview env but the database branch attached seems to always be preview/HEAD which is shared between all preview env however I was expecting that each deployment (PR) would have its own database branch. Are my expectations wrong or what could be wrong?
4 Replies
gradual-turquoise
gradual-turquoise5d ago
Hey! Your setup should indeed create a Neon branch per PR. Do you have a hard coded DATABASE_URL, if so it might be overriding the integration. Likewise, do you see any branches being created in the Neon console?
fair-rose
fair-roseOP4d ago
Hey @Sam ! In Neon I see branches "main" and "preview/HEAD". When I delete "preview/HEAD" branch in Neon and run in a freshly cloned repo "vercel" command to build and deploy a new preview deployment, then "preview/HEAD" was not re-created 🤔 (tried to make a very simple test case as the actual CI process is run in Github Actions. In Vercel project settings I see that DATABASE_URL is Neon managed env var. When created a new PR in Github, then "preview/HEAD" branch was re-created in Neon. For the context, Github Action workflow chunk regarding Vercel is the following:
- name: Pull Vercel project settings
run: vercel pull --yes --environment=${{ github.ref_name == 'main' && 'production' || 'preview' }} --token ${{ secrets.VERCEL_TOKEN }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

- name: Build with Vercel
run: |
pnpm check
vercel build ${{ github.ref_name == 'main' && '--prod' || '' }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

- name: Deploy to Vercel
run: |
vercel deploy --token ${{ secrets.VERCEL_TOKEN }} \
--scope ${{ secrets.VERCEL_TEAM_ID }} \
${{ github.ref_name == 'main' && '--prod' || '' }} \
--prebuilt \
--no-wait
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
- name: Pull Vercel project settings
run: vercel pull --yes --environment=${{ github.ref_name == 'main' && 'production' || 'preview' }} --token ${{ secrets.VERCEL_TOKEN }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

- name: Build with Vercel
run: |
pnpm check
vercel build ${{ github.ref_name == 'main' && '--prod' || '' }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

- name: Deploy to Vercel
run: |
vercel deploy --token ${{ secrets.VERCEL_TOKEN }} \
--scope ${{ secrets.VERCEL_TEAM_ID }} \
${{ github.ref_name == 'main' && '--prod' || '' }} \
--prebuilt \
--no-wait
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
gradual-turquoise
gradual-turquoise4d ago
I haven't seen the Vercel <-> Neon integration being used like this, so I don't know 100%. I believe you're facing these issues because you're building outside of Vercel, skipping the normal build lifecycle where the Neon integration creates the per-PR branch and injects the branch-specific DATABASE_URL.
fair-rose
fair-roseOP22h ago
Understood. However when running "vercel" locally and deploying directly (which builds on Vercel) is it expected that Neon branch is created or not in that case? If I get the branching working in a simpler case then I could debug myself my more complex CI flow. @Sam Neon branching works, when letting Vercel build the deployment and skipping Github Actions entirely. It is a "me"-issue then. Thanks and solved.

Did you find this page helpful?