Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Edge Function deployments #21394

Open
janpio opened this issue Oct 6, 2023 · 29 comments
Open

Support Edge Function deployments #21394

janpio opened this issue Oct 6, 2023 · 29 comments

Comments

@janpio
Copy link
Member

janpio commented Oct 6, 2023

⚠️ Current Status: See this release announcement! 🥳


Currently Prisma can only be used in Edge Function deployments when you use Prisma Accelerate and @prisma/client/edge. Although we like our own product very much, that should not be a requirement to use Prisma in any environment you want to develop and deploy your app.

We want to support deploying apps using Prisma Client to any Edge Function environment.

Please help us by filling this short survey: https://pris.ly/survey/edge-functions If you leave your email address, you can also be considered for early access for testing and evaluating this. Thanks.

@marvinvr
Copy link

Is there any rough timeline on when this will be able for preview / released? I need a temporary fix for an issue I'm having which this would make obsolete and it would be great to have this context. Can't wait to see this, thanks!

@janpio
Copy link
Member Author

janpio commented Nov 13, 2023

No timeline for preview or release, but we expect to send out first invites to early access to survey participants in days or weeks, not months.

@croossin
Copy link

Any updates to a more GA or widespread release?

@janpio
Copy link
Member Author

janpio commented Jan 22, 2024

We are working towards a public preview release of this soon.

@gramliu
Copy link

gramliu commented Feb 21, 2024

Hi @janpio, many thanks to you and the team for rolling out support for this issue. That being said, I saw on another thread that MongoDB is not supported yet with this rollout. Is this on your roadmap/is there a timeline for this?
I use Mongo as my primary db, but have been experiencing cold start issues with accelerate, so I'd love to be able to use my native mongo connection string.

@janpio
Copy link
Member Author

janpio commented Feb 21, 2024

@gramliu Unfortunately, we are not aware of any way to talk to MongoDB databases from edge function environments, there are edge compatible no drivers for MongoDB.

We need a driver that uses a HTTP or Websocket API (like the Neon and PlanetScale serverless drivers), as that is the preferred communication method for edge function deployments, or a database driver that is supported on one of those platforms like node-postgres that works on Cloudflare Workers via their connect() TCP API. I am not aware of any MongoDB driver that supports this.

(Besides: Prisma Accelerate is built partially to avoid cold start issues with your database connection, so I suggest you get in contact with our Platform support team to figure out what is going on there.)

@TimKieu
Copy link

TimKieu commented Feb 28, 2024

Sorry Prisma. I can't wait and move to Kysely.

@coratype
Copy link

coratype commented Mar 5, 2024

Is there any update on when this will be ready? I have a product I'm ready to deploy and I'd prefer to use Cloudflare Workers instead of Vercel but would have to rewrite a lot of code to remove Prisma and use something else. I also generally prefer Prisma as a product in general as well as the people who work on it. Thanks.

@mrmueller
Copy link

mrmueller commented Mar 5, 2024

@coratype I don't know your use case but i would recommend using Prisma Accelerate as a workaround until this is ready.
It only requires setting up Prisma Accelerate for your existing DB and changing the connection string to Prisma Accelerate in your Code. Once Prisma can run on edge, you should be able to revert to the direct DB connection string.

I am currently doing that for my MVP. For this small thing, the free "Starter" plan is sufficient for now.

@coratype
Copy link

coratype commented Mar 5, 2024

It's a social media application so requests will be high, I'd have to consider the costs first but I'll look into it

@janpio
Copy link
Member Author

janpio commented Mar 5, 2024

Yes, this is currently in Early Access and we expect to open it up for Preview publicly soon. Not that of course we do not know what our users - like you - will then actually find for us to fix, so it is super hard to say when this Preview will really be ready for production use. Generally using databases from edge functions environments is a pretty new thing, compared to the old school Node or Serverless environments.

@brunocascio
Copy link

I'm not running a production app but building one without any deadline (personal project)
It's a remix app using prisma + D1 and deployed with wrangler.
So I'm here to provide feedback as soon it's available :D

By using cloudflare deployment and maintenance is REALLY cheaper compared to vercel, sst or any other provider due to bandwidth in cf is almost free.

P.S.: I was digging into the D1 code since it's available under lastest release of prisma, and so far it's working good. My 2c I'll share when gets preview stage:

  1. createdAt, updatedAt Timestamps thrown an error of parsing the colum (seems to be adapter-d1 treating it as a float instead of an int)
  2. Migrations, not sure how to properly handle them, so it sounds like a worker is needed to run them or a way to convert migrations into a sql file that can be invoked with wrangler.

@coratype
Copy link

coratype commented Mar 5, 2024

Thanks for working on it, in that case I'll hold off on launch, albeit I did apply for the preview

@janpio
Copy link
Member Author

janpio commented Mar 12, 2024

Hey everyone!

We just released Prisma ORM version 5.11.0 which includes a preview feature for Edge Functions support via Cloudflare Workers and Pages and Vercel Edge Functions and Middleware in Prisma ORM 🥳

Please give it a try, and let us know how it goes! If you encounter any problems, please create a new bug report issue, or if the problem is driver adapter specific, use the feedback discussions for @prisma/adapter-neon, @prisma/adapter-planetscale, @prisma/adapter-libsql / Turso or @prisma/adapter-pg 🙇

PS: We are also working on support for Cloudflare D1, and expect to share news in this feature request issue soon. (Early Access for that is already in progress)

@janpio janpio added the status/is-preview-feature This feature request is currently available as a Preview feature. label Mar 12, 2024
@atanaskanchev
Copy link

Is there a plan to roll out support for Supabase on the edge?

@Jolg42
Copy link
Member

Jolg42 commented Mar 13, 2024

@brunocascio Could you open an issue? About your problem with the D1 adapter:

createdAt, updatedAt Timestamps thrown an error of parsing the colum (seems to be adapter-d1 treating it as a float instead of an int).

I could not reproduce this, but I'm very curious to reproduce this and would need your help for this.
Make sure to add an example and which version of Prisma packages you are using.

About Migrations, we definitely want to have a better experience there, so stay tuned 📻

@brunocascio
Copy link

@brunocascio Could you open an issue? About your problem with the D1 adapter:

createdAt, updatedAt Timestamps thrown an error of parsing the colum (seems to be adapter-d1 treating it as a float instead of an int).

I could not reproduce this, but I'm very curious to reproduce this and would need your help for this. Make sure to add an example and which version of Prisma packages you are using.

About Migrations, we definitely want to have a better experience there, so stay tuned 📻

Sure! -> #23479

@johannbuscail
Copy link

@janpio Are you going to support supabase ? If yes, when ?

@janpio
Copy link
Member Author

janpio commented Mar 16, 2024

@johannbuscail @atanaskanchev Not yet, but that is definitely an option we can look into. Go and leave a 👍 reaction on this new issue I created to track the demand for these platforms: #23512 Thanks!

@vegandiet705
Copy link

@janpio Any plan on supporting MongoDB ? Thanks !

@janpio
Copy link
Member Author

janpio commented Apr 9, 2024

There is unfortunately no database driver for MongoDB available that works on edge function deployments. As soon as that changes we can consider adding support for it as well - but this is unfortunately out of our control.

@adamchipperfield
Copy link

Hey @janpio. I'm wondering if I've misunderstood the recent feature previews. Initially, I used the Postgres adapter in my Next.js middleware. I understand why that didn't work now, because it's trying to run in an edge runtime. Total misstep on my part.

However, I'm now using the Neon adapter which in theory supports edge runtimes (right?). But I'm getting all sorts of errors, which I'm happy to list out. I just wanted to get a sense check that it's even possible to use this in Next.js?

I'm only working locally right now, so my thinking is isolated to Next.js and not Vercel hosting. Here's how I've got my client configured:

import { Pool } from '@neondatabase/serverless'
import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@prisma/client'

export const db = new PrismaClient({
  adapter: new PrismaNeon(
    new Pool({ connectionString: process.env.DATABASE_URL })
  )
})

Am I going in the right direction? Or is this a non-starter right now?

@janpio
Copy link
Member Author

janpio commented Apr 10, 2024

That should indeed work. Please open a new bug issue with more information so we can debug this. Thanks.

@adamchipperfield
Copy link

That should indeed work. Please open a new bug issue with more information so we can debug this. Thanks.

@janpio Good to know! Another detail is I'm using a local Postgres database and not Vercel Postgres. That should also still work, yes?

@janpio
Copy link
Member Author

janpio commented Apr 10, 2024

Probably not, as Vercel Postgres and Neon Postgres have a proxy in front of their database that allows the serverless driver to talk to it via Websockets instead of TCP (which is the default communication method with databases, but not supported in edge function environments or Next.js middleware). You can see here how we run that proxy ourselves locally so the driver adapter can work with a local PostgreSQL database:

neon_wsproxy:
image: ghcr.io/neondatabase/wsproxy:latest
environment:
APPEND_PORT: 'postgres-16:5432'
ALLOW_ADDR_REGEX: '.*'
LOG_TRAFFIC: 'true'
LOG_CONN_INFO: 'true'
ports:
- '5488:80'
depends_on:
- postgres-16
restart: unless-stopped
healthcheck:
test: ['CMD', 'nc', '-z', '127.0.0.1', '80']
interval: 5s
timeout: 2s
retries: 20

See here for someone else sharing how they got that to work: #21310 (comment)

@janpio
Copy link
Member Author

janpio commented Apr 26, 2024

See #21394 (comment) for links 🔒

@prisma prisma locked as resolved and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests