neondatabase / preview-branches-with-vercel

Example project that shows how you can create a branch for every preview deployment on Vercel using GitHub actions
29 stars 11 forks source link

How does the Vercel preview environment get the right `DATABASE_URL`? #7

Closed StevenLangbroek closed 1 year ago

StevenLangbroek commented 1 year ago

Hey folks! Not really a bug report, more of a question. I got here by reading the blog post, but am unable to locate exactly how a specific Vercel preview deployment becomes aware of the DATABASE_URL (for this specific Neon branch) it should connect to? Does the appending DATABASE_URL to .env during migrate get merged with the .env file pulled in with vercel pull?

StevenLangbroek commented 1 year ago

@m-abdelwahab any chance for input from Neon's side? :)

m-abdelwahab commented 1 year ago

Does the appending DATABASE_URL to .env during migrate get merged with the .env file pulled in with vercel pull

@StevenLangbroek Yes, exactly! That's what this part does.

      - name: Run Prisma Migrate
        run: |
          touch .env
          echo DATABASE_URL=${{ steps.create_branch.outputs.db_url_with_pooler}}/neondb >> .env
          echo DIRECT_DATABASE_URL=${{ steps.create_branch.outputs.db_url}}/neondb >> .env
          npx prisma generate
          npx prisma migrate deploy

I just noticed that this part wasn't explained in the blog post. I'll make sure to update it. :)

Thank you so much for reaching out, and sorry for the delayed response. I didn't get notified when you created the issue :)

StevenLangbroek commented 1 year ago

Awesome, thanks @m-abdelwahab! We should be on production with our first use then early next week 🚀

m-abdelwahab commented 1 year ago

No problem @StevenLangbroek! Don't hesitate to reach out if you have any other questions or need help with anything :). You can reach out at support@neon.tech or DM me on Twitter

alxclark commented 7 months ago

Hi @m-abdelwahab 👋🏼 Have you tried edge functions with this setup ? From my testing it seems like Vercel functions only pull the preview environment variables from the Vercel dashboard and don't reuse the local environment variables available at build time.

I'm curious if you found a way around that issue. Thanks!