diff --git a/src/content/docs/d1/tutorials/d1-and-prisma-orm/index.mdx b/src/content/docs/d1/tutorials/d1-and-prisma-orm/index.mdx index 85eb80126ba907a..9f0ed6845e07f32 100644 --- a/src/content/docs/d1/tutorials/d1-and-prisma-orm/index.mdx +++ b/src/content/docs/d1/tutorials/d1-and-prisma-orm/index.mdx @@ -1,5 +1,5 @@ --- -updated: 2025-05-16 +updated: 2025-06-03 difficulty: Beginner content_type: Tutorial pcx_content_type: tutorial @@ -83,14 +83,11 @@ Open your `schema.prisma` file and adjust the `generator` block to reflect as fo ```diff generator client { provider = "prisma-client-js" -+ previewFeatures = ["driverAdapters"] + output = "../src/generated/prisma" + previewFeatures = ["driverAdapters"] } ``` -:::note -Do not specify an `output` destination in the `generator client` block. Instead, allow prisma to generate the files in the default output path. -::: - ### 3. Create your D1 database In this step, you will set up your D1 database. You can create a D1 database via the [Cloudflare dashboard](https://dash.cloudflare.com), or via `wrangler`. This tutorial will use the `wrangler` CLI. @@ -129,6 +126,8 @@ name = "prisma-d1-example" main = "src/index.ts" compatibility_date = "2024-03-20" compatibility_flags = ["nodejs_compat"] +[observability] +enabled = true [[d1_databases]] binding = "DB" # i.e. available in your Worker on env.DB @@ -146,7 +145,13 @@ Next, you will create a database table in the database to send queries to D1 usi [Prisma Migrate](https://www.prisma.io/docs/orm/prisma-migrate/understanding-prisma-migrate/overview) does not support D1 yet, so you cannot follow the default migration workflows using `prisma migrate dev` or `prisma db push`. -However, D1 has a [migration system](/d1/reference/migrations), and the Prisma CLI provides tools that allow you to generate SQL statements for schema changes. In the following steps, you will use D1's migration system and the Prisma CLI to create and run a migration against your database. +:::note + +Prisma Migrate for D1 is currently in Early Access. If you want to try it out, you can follow the instructions on the [Prisma documentation](https://www.prisma.io/docs/orm/overview/databases/cloudflare-d1#using-prisma-migrate-via-a-driver-adapter-in-prismaconfigts-early-access). + +::: + +D1 uses [migrations](/d1/reference/migrations) for managing schema changes, and the Prisma CLI can help generate the necessary SQL for those updates. In the steps below, you'll use both tools to create and apply a migration to your database. First, create a new migration using `wrangler`: @@ -259,7 +264,7 @@ To query your database from the Worker using Prisma ORM, you need to: Open `src/index.ts` and replace the entire content with the following: ```ts -import { PrismaClient } from "@prisma/client"; +import { PrismaClient } from './generated/prisma/'; import { PrismaD1 } from "@prisma/adapter-d1"; export interface Env {