diff --git a/content/800-guides/410-cloudflare-workers.mdx b/content/800-guides/410-cloudflare-workers.mdx index e9d264d6e4..f51b3da407 100644 --- a/content/800-guides/410-cloudflare-workers.mdx +++ b/content/800-guides/410-cloudflare-workers.mdx @@ -69,7 +69,7 @@ This will create: Cloudflare Workers needs Node.js compatibility enabled to work with Prisma. Add the `nodejs_compat` compatibility flag to your `wrangler.jsonc`: -```jsonc file=wrangler.jsonc +```json file=wrangler.jsonc { "name": "prisma-cloudflare-worker", "main": "src/index.ts", @@ -80,33 +80,9 @@ Cloudflare Workers needs Node.js compatibility enabled to work with Prisma. Add } ``` -### 2.3. Add environment types to Prisma config -Add the `Env` interface to your `prisma.config.ts` to provide type safety for environment variables: +### 2.3. Define your Prisma Schema -```typescript file=prisma.config.ts -import "dotenv/config"; -import { defineConfig, env } from "prisma/config"; - -//add-start -export interface Env { - DATABASE_URL: string; -} -//add-end - -import { defineConfig, env } from 'prisma/config'; -export default defineConfig({ - schema: 'prisma/schema.prisma', - migrations: { - path: 'prisma/migrations', - }, - datasource: { - url: env('DATABASE_URL'), - }, -}); -``` - -### 2.4. Define your Prisma schema In the `prisma/schema.prisma` file, add the following `User` model and set the runtime to `cloudflare`: @@ -131,9 +107,15 @@ model User { //add-end ``` +:::note + +Both the `cloudflare` and `workerd` runtimes are supported. Read more about runtimes [here](/orm/prisma-schema/overview/generators#field-reference). + +::: + This creates a `User` model with an auto-incrementing ID, email, and name. -### 2.5. Configure Prisma scripts +### 2.4. Configure Prisma scripts Add the following scripts to your `package.json` to work with Prisma in the Cloudflare Workers environment: @@ -150,7 +132,7 @@ Add the following scripts to your `package.json` to work with Prisma in the Clou } ``` -### 2.6. Run migrations and generate Prisma Client +### 2.5. Run migrations and generate Prisma Client Now, run the following command to create the database tables: diff --git a/static/img/guides/prisma-cloudflare-workers-cover.png b/static/img/guides/prisma-cloudflare-workers-cover.png new file mode 100644 index 0000000000..27d145b6d7 Binary files /dev/null and b/static/img/guides/prisma-cloudflare-workers-cover.png differ