From a49d7755ada8ffafa9ce5eab58c9cc95bf054282 Mon Sep 17 00:00:00 2001 From: Nurul Sundarani Date: Tue, 11 Nov 2025 19:28:46 +0530 Subject: [PATCH 1/2] (feat) Update guides to use prisma.config.ts --- content/800-guides/010-data-migration.mdx | 31 +++++++++- .../020-implementing-schema-changes.mdx | 29 +++++++++ .../800-guides/030-migrate-from-typeorm.mdx | 29 +++++++++ .../800-guides/040-migrate-from-sequelize.mdx | 29 +++++++++ .../800-guides/050-migrate-from-mongoose.mdx | 29 +++++++++ .../800-guides/060-migrate-from-drizzle.mdx | 35 ++++++++++- content/800-guides/070-cloudflare-d1.mdx | 8 ++- content/800-guides/080-turborepo.mdx | 25 ++++++-- content/800-guides/090-nextjs.mdx | 8 +-- content/800-guides/100-nuxt.mdx | 33 ++++++++++- content/800-guides/130-docker.mdx | 27 +++++++++ .../140-use-prisma-in-pnpm-workspaces.mdx | 29 +++++++++ content/800-guides/150-multiple-databases.mdx | 50 +++++++++++++++- content/800-guides/160-tanstack-start.mdx | 2 - content/800-guides/170-react-router-7.mdx | 2 - content/800-guides/180-solid-start.mdx | 2 - content/800-guides/190-data-dog.mdx | 29 +++++++++ content/800-guides/190-sveltekit.mdx | 2 - content/800-guides/200-clerk-nextjs.mdx | 29 +++++++++ content/800-guides/210-shopify.mdx | 29 +++++++++ content/800-guides/220-astro.mdx | 2 - content/800-guides/230-betterauth-nextjs.mdx | 35 +++++++++-- .../800-guides/300-supabase-accelerate.mdx | 29 ++++++++- content/800-guides/310-neon-accelerate.mdx | 29 ++++++++- .../320-permit-io-access-control.mdx | 1 - content/800-guides/330-github-actions.mdx | 30 ++++++++++ content/800-guides/340-ai-sdk-nextjs.mdx | 1 - content/800-guides/350-authjs-nextjs.mdx | 1 - .../800-guides/360-embed-studio-nextjs.mdx | 2 - content/800-guides/370-bun.mdx | 9 +-- content/800-guides/390-hono.mdx | 8 +-- content/800-guides/999-making-guides.mdx | 59 ++++++++++++++++--- 32 files changed, 609 insertions(+), 54 deletions(-) diff --git a/content/800-guides/010-data-migration.mdx b/content/800-guides/010-data-migration.mdx index 24b98c97b6..9f8893c69c 100644 --- a/content/800-guides/010-data-migration.mdx +++ b/content/800-guides/010-data-migration.mdx @@ -61,7 +61,36 @@ model Post { } ``` -### 1.2. Create a development branch +### 1.2. Configure Prisma + +Create a `prisma.config.ts` file in the root of your project with the following content: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager: + +```bash +npm install dotenv +``` + +::: + +### 1.3. Create a development branch Create a new branch for your changes: diff --git a/content/800-guides/020-implementing-schema-changes.mdx b/content/800-guides/020-implementing-schema-changes.mdx index a5d8342766..83a4f30211 100644 --- a/content/800-guides/020-implementing-schema-changes.mdx +++ b/content/800-guides/020-implementing-schema-changes.mdx @@ -47,6 +47,35 @@ Source-controlling the `schema.prisma` file is not enough - you must include you - Customized migrations contain information that cannot be represented in the Prisma schema - The `prisma migrate deploy` command only runs migration files +### 1.3. Configure Prisma + +Create a `prisma.config.ts` file in the root of your project with the following content: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager: + +```bash +npm install dotenv +``` + +::: + ## 2. Incorporate team changes ### 2.1. Pull latest changes diff --git a/content/800-guides/030-migrate-from-typeorm.mdx b/content/800-guides/030-migrate-from-typeorm.mdx index 210e5bd1be..4b852ac2b9 100644 --- a/content/800-guides/030-migrate-from-typeorm.mdx +++ b/content/800-guides/030-migrate-from-typeorm.mdx @@ -51,6 +51,35 @@ Update the `DATABASE_URL` in the `.env` file with your database connection strin DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE" ``` +### 2.3. Configure Prisma + +Create a `prisma.config.ts` file in the root of your project with the following content: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager: + +```bash +npm install dotenv +``` + +::: + ## 3. Migrate the database schema ### 3.1. Introspect your database diff --git a/content/800-guides/040-migrate-from-sequelize.mdx b/content/800-guides/040-migrate-from-sequelize.mdx index 4abf2e8fac..bc98456af4 100644 --- a/content/800-guides/040-migrate-from-sequelize.mdx +++ b/content/800-guides/040-migrate-from-sequelize.mdx @@ -78,6 +78,35 @@ Update the `DATABASE_URL` in the `.env` file with your database connection strin DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE" ``` +### 1.3. Configure Prisma + +Create a `prisma.config.ts` file in the root of your project with the following content: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager: + +```bash +npm install dotenv +``` + +::: + ## 2. Migrate the database schema ### 2.1. Introspect your database diff --git a/content/800-guides/050-migrate-from-mongoose.mdx b/content/800-guides/050-migrate-from-mongoose.mdx index 3143c942f0..e9a4b2b306 100644 --- a/content/800-guides/050-migrate-from-mongoose.mdx +++ b/content/800-guides/050-migrate-from-mongoose.mdx @@ -78,6 +78,35 @@ Update the `DATABASE_URL` in the `.env` file with your MongoDB connection string DATABASE_URL="mongodb://USER:PASSWORD@HOST:PORT/DATABASE" ``` +### 1.3. Configure Prisma + +Create a `prisma.config.ts` file in the root of your project with the following content: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager: + +```bash +npm install dotenv +``` + +::: + ## 2. Migrate the database schema ### 2.1. Introspect your database diff --git a/content/800-guides/060-migrate-from-drizzle.mdx b/content/800-guides/060-migrate-from-drizzle.mdx index 53b6e57d18..0fe8942aca 100644 --- a/content/800-guides/060-migrate-from-drizzle.mdx +++ b/content/800-guides/060-migrate-from-drizzle.mdx @@ -150,7 +150,36 @@ datasource db { Once that's done, you can configure your [database connection URL](/orm/reference/connection-urls) in the `.env` file. Drizzle and Prisma ORM use the same format for connection URLs, so your existing connection URL should work fine. -### 2.3. Introspect your database using Prisma ORM +### 2.3. Configure Prisma + +Create a `prisma.config.ts` file in the root of your project with the following content: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager: + +```bash +npm install dotenv +``` + +::: + +### 2.4. Introspect your database using Prisma ORM With your connection URL in place, you can [introspect](/orm/prisma-schema/introspection) your database to generate your Prisma models: @@ -170,7 +199,7 @@ model todo { The generated Prisma model represents a database table. Prisma models are the foundation for your programmatic Prisma Client API which allows you to send queries to your database. -### 2.4. Create a baseline migration +### 2.5. Create a baseline migration To continue using Prisma Migrate to evolve your database schema, you will need to [baseline your database](/orm/prisma-migrate/getting-started). @@ -202,7 +231,7 @@ The command will mark `0_init` as applied by adding it to the `_prisma_migration You now have a baseline for your current database schema. To make further changes to your database schema, you can update your Prisma schema and use `prisma migrate dev` to apply the changes to your database. -### 2.5. Adjust the Prisma schema (optional) +### 2.6. Adjust the Prisma schema (optional) Models that are generated via introspection currently _exactly_ map to your database tables. In this section, you'll learn how you can adjust the naming of the Prisma models to adhere to [Prisma ORM's naming conventions](/orm/reference/prisma-schema-reference#naming-conventions). diff --git a/content/800-guides/070-cloudflare-d1.mdx b/content/800-guides/070-cloudflare-d1.mdx index 7264a75355..9dbb973915 100644 --- a/content/800-guides/070-cloudflare-d1.mdx +++ b/content/800-guides/070-cloudflare-d1.mdx @@ -179,7 +179,7 @@ CLOUDFLARE_D1_TOKEN="F8Cg..." Ensure that you have a `prisma.config.ts` file set up in the root of your project with a [driver adapter](/orm/reference/prisma-config-reference#adapter) defined. -```ts +```typescript file=prisma.config.ts import type { PrismaConfig } from 'prisma'; import { PrismaD1 } from '@prisma/adapter-d1'; @@ -191,6 +191,12 @@ export default { adapter: true, }, schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: process.env.DATABASE_URL!, + }, async adapter() { return new PrismaD1({ CLOUDFLARE_D1_TOKEN: process.env.CLOUDFLARE_D1_TOKEN!, diff --git a/content/800-guides/080-turborepo.mdx b/content/800-guides/080-turborepo.mdx index 6580182f7b..f0dd46e806 100644 --- a/content/800-guides/080-turborepo.mdx +++ b/content/800-guides/080-turborepo.mdx @@ -94,7 +94,7 @@ Next, install the required dependencies to use Prisma ORM. Use your preferred pa ```terminal npm install prisma --save-dev -npm install @prisma/client +npm install @prisma/client dotenv ``` @@ -103,7 +103,7 @@ npm install @prisma/client ```terminal yarn add prisma --dev -yarn add @prisma/client +yarn add @prisma/client dotenv ``` @@ -112,7 +112,7 @@ yarn add @prisma/client ```terminal pnpm add prisma --save-dev -pnpm add @prisma/client +pnpm add @prisma/client dotenv ``` @@ -222,6 +222,23 @@ model Post { //add-end ``` +The `prisma.config.ts` file created in the `packages/database` directory should look like this: + +```typescript file=packages/database/prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + :::warning It is recommended to add `../generated/prisma` to the `.gitignore` file because it contains platform-specific binaries that can cause compatibility issues across different environments. @@ -335,7 +352,7 @@ Navigate to the project root and run the following command to automatically migr -Generate your `prisma.schema` +Generate your `schema.prisma` To generate the types from Prisma schema, from the project root run: diff --git a/content/800-guides/090-nextjs.mdx b/content/800-guides/090-nextjs.mdx index 445d252b3e..1b55438503 100644 --- a/content/800-guides/090-nextjs.mdx +++ b/content/800-guides/090-nextjs.mdx @@ -139,17 +139,17 @@ This creates two models: `User` and `Post`, with a one-to-many relationship betw To get access to the variables in the `.env` file, they can either be loaded by your runtime, or by using `dotenv`. Include an import for `dotenv` at the top of the `prisma.config.ts` -```ts +```typescript file=prisma.config.ts //add-start import 'dotenv/config' //add-end import { defineConfig, env } from 'prisma/config'; + export default defineConfig({ schema: 'prisma/schema.prisma', migrations: { path: 'prisma/migrations' }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, @@ -218,9 +218,10 @@ main(); Now, tell Prisma how to run this script by updating your `prisma.config.ts`: -```ts file=prisma.config.ts +```typescript file=prisma.config.ts import 'dotenv/config' import { defineConfig, env } from 'prisma/config'; + export default defineConfig({ schema: 'prisma/schema.prisma', migrations: { @@ -229,7 +230,6 @@ export default defineConfig({ seed: `tsx prisma/seed.ts`, //add-end }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, diff --git a/content/800-guides/100-nuxt.mdx b/content/800-guides/100-nuxt.mdx index c35659aa03..11aa72da40 100644 --- a/content/800-guides/100-nuxt.mdx +++ b/content/800-guides/100-nuxt.mdx @@ -62,7 +62,36 @@ To follow this guide, ensure you have the following: }); ``` -## 2. Setup Prisma ORM by running the development server locally +## 2. Configure Prisma + +Before running the development server, create a `prisma.config.ts` file in the root of your project to manage environment variables and configuration: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables: + +```bash +npm install dotenv +``` + +::: + +## 3. Setup Prisma ORM by running the development server locally After configuring your Nuxt project with the Prisma module, the next step is to set up Prisma ORM. This process begins by starting the development server, which automatically configures Prisma with a [SQLite database](/orm/overview/databases/sqlite). @@ -121,7 +150,7 @@ Once the setup flow has terminated, it: 5. Installed and generated [Prisma Client](https://da-2255.docs-51g.pages.dev/orm/reference/prisma-client-reference) which enables you to query your DB. 6. Installed [Prisma Studio](/orm/tools/prisma-studio). -When the Prisma setup is complete, the development server should start on `https://localhost:3000`. +When the Prisma setup is complete, the development server should start on `https://localhost:3000`. Next, stop the server, as we need to make some code changes. diff --git a/content/800-guides/130-docker.mdx b/content/800-guides/130-docker.mdx index b6d6e1684d..c8c24a5838 100644 --- a/content/800-guides/130-docker.mdx +++ b/content/800-guides/130-docker.mdx @@ -126,6 +126,33 @@ In the `schema.prisma` file, we specify a [custom `output` path](/orm/prisma-cli ::: +Now, create a `prisma.config.ts` file in the root of your project: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables: + +```bash +npm install dotenv +``` + +::: + ### 1.4. Create an Express.js server With the Prisma schema in place, let's create an Express.js server to interact with the database. Start by creating an `index.js` file: diff --git a/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx b/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx index 388b68f1c8..45757bd01a 100644 --- a/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx +++ b/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx @@ -161,6 +161,35 @@ model User { //add-end ``` +Now, create a `prisma.config.ts` file in the `database` package to configure Prisma: + +```typescript file=database/prisma.config.ts +// add-start +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +// add-end +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables from the `.env` file: + +```terminal +pnpm add dotenv +``` + +::: + Next, add helper scripts to your `package.json` to simplify Prisma commands: ```json file=database/package.json diff --git a/content/800-guides/150-multiple-databases.mdx b/content/800-guides/150-multiple-databases.mdx index f3dd98f223..f304134f9c 100644 --- a/content/800-guides/150-multiple-databases.mdx +++ b/content/800-guides/150-multiple-databases.mdx @@ -146,6 +146,35 @@ model User { //add-end ``` +Create a `prisma.config.ts` file for the user database: + +```typescript file=prisma-user-database/prisma.config.ts +//add-start +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma-user-database/schema.prisma', + migrations: { + path: 'prisma-user-database/migrations', + }, + datasource: { + url: env('PPG_USER_DATABASE_URL'), + }, +}); +//add-end +``` + +:::note + +You'll need to install the `dotenv` package if you haven't already: + +```terminal +npm install dotenv +``` + +::: + Your user database schema is now ready. ### 2.2. Create a Prisma Postgres instance for post data @@ -197,12 +226,31 @@ datasource db { //add-start model Post { id Int @id @default(autoincrement()) - title String + title String content String? } //add-end ``` +Create a `prisma.config.ts` file for the post database: + +```typescript file=prisma-post-database/prisma.config.ts +//add-start +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma-post-database/schema.prisma', + migrations: { + path: 'prisma-post-database/migrations', + }, + datasource: { + url: env('PPG_POST_DATABASE_URL'), + }, +}); +//add-end +``` + Your post database schema is now set. ### 2.3. Add helper scripts and migrate the schemas diff --git a/content/800-guides/160-tanstack-start.mdx b/content/800-guides/160-tanstack-start.mdx index 971908e4d4..a288dbd61b 100644 --- a/content/800-guides/160-tanstack-start.mdx +++ b/content/800-guides/160-tanstack-start.mdx @@ -390,7 +390,6 @@ export default defineConfig({ migrations: { path: 'prisma/migrations', }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, @@ -468,7 +467,6 @@ export default defineConfig({ seed: `tsx prisma/seed.ts`, //add-end }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, diff --git a/content/800-guides/170-react-router-7.mdx b/content/800-guides/170-react-router-7.mdx index 6cd1474854..c953dd4990 100644 --- a/content/800-guides/170-react-router-7.mdx +++ b/content/800-guides/170-react-router-7.mdx @@ -129,7 +129,6 @@ export default defineConfig({ migrations: { path: 'prisma/migrations', }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, @@ -209,7 +208,6 @@ export default defineConfig({ seed: `tsx prisma/seed.ts`, //add-end }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, diff --git a/content/800-guides/180-solid-start.mdx b/content/800-guides/180-solid-start.mdx index 705eaf4a58..85e99aeff7 100644 --- a/content/800-guides/180-solid-start.mdx +++ b/content/800-guides/180-solid-start.mdx @@ -149,7 +149,6 @@ export default defineConfig({ migrations: { path: 'prisma/migrations', }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, @@ -230,7 +229,6 @@ export default defineConfig({ seed: `tsx prisma/seed.ts`, //add-end }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, diff --git a/content/800-guides/190-data-dog.mdx b/content/800-guides/190-data-dog.mdx index 41d7894df3..fcba863180 100644 --- a/content/800-guides/190-data-dog.mdx +++ b/content/800-guides/190-data-dog.mdx @@ -182,6 +182,35 @@ model Post { //add-end ``` +Create a `prisma.config.ts` file to configure Prisma: + +```typescript file=prisma.config.ts +//add-start +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +//add-end +``` + +:::note + +You'll need to install the `dotenv` package if you haven't already: + +```terminal +npm install dotenv +``` + +::: + ### 2.3. Generate the Prisma Client and run migrations Generate the Prisma Client and apply your schema to your database: diff --git a/content/800-guides/190-sveltekit.mdx b/content/800-guides/190-sveltekit.mdx index 9031029e71..7625b273aa 100644 --- a/content/800-guides/190-sveltekit.mdx +++ b/content/800-guides/190-sveltekit.mdx @@ -143,7 +143,6 @@ export default defineConfig({ migrations: { path: 'prisma/migrations', }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, @@ -223,7 +222,6 @@ export default defineConfig({ seed: `tsx prisma/seed.ts`, //add-end }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, diff --git a/content/800-guides/200-clerk-nextjs.mdx b/content/800-guides/200-clerk-nextjs.mdx index 4d4409fa5d..e1fcfd2810 100644 --- a/content/800-guides/200-clerk-nextjs.mdx +++ b/content/800-guides/200-clerk-nextjs.mdx @@ -286,6 +286,35 @@ model Post { This will create two models: `User` and `Post`, with a one-to-many relationship between them. +Create a `prisma.config.ts` file to configure Prisma: + +```typescript file=prisma.config.ts showLineNumbers +//add-start +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +//add-end +``` + +:::note + +You'll need to install the `dotenv` package: + +```terminal +npm install dotenv +``` + +::: + Now, run the following command to create the database tables and generate the Prisma Client: ```terminal diff --git a/content/800-guides/210-shopify.mdx b/content/800-guides/210-shopify.mdx index b8a9eca491..81c9e4afa9 100644 --- a/content/800-guides/210-shopify.mdx +++ b/content/800-guides/210-shopify.mdx @@ -85,6 +85,35 @@ model Session { } ``` +Create a `prisma.config.ts` file to configure Prisma: + +```typescript file=prisma.config.ts +//add-start +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +//add-end +``` + +:::note + +Since Shopify apps typically have dotenv pre-installed, you should already have access to it. If not, install it with: + +```terminal +npm install dotenv +``` + +::: + To enable your app to store notes for each product, let's add a new `ProductNote` model to your Prisma schema. This model will allow you to save and organize notes linked to individual products in your database through the `productGid` field. diff --git a/content/800-guides/220-astro.mdx b/content/800-guides/220-astro.mdx index ccd930ce0b..ad28d9a98c 100644 --- a/content/800-guides/220-astro.mdx +++ b/content/800-guides/220-astro.mdx @@ -130,7 +130,6 @@ export default defineConfig({ migrations: { path: 'prisma/migrations', }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, @@ -223,7 +222,6 @@ export default defineConfig({ path: 'prisma/migrations', seed: `tsx prisma/seed.ts`, }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, diff --git a/content/800-guides/230-betterauth-nextjs.mdx b/content/800-guides/230-betterauth-nextjs.mdx index 5a048fb22c..0f9f756363 100644 --- a/content/800-guides/230-betterauth-nextjs.mdx +++ b/content/800-guides/230-betterauth-nextjs.mdx @@ -88,7 +88,36 @@ This will create: - A `.env` file containing the `DATABASE_URL` at the project root. - An `output` directory for the generated Prisma Client as `better-auth/generated/prisma`. -### 2.2. Configure the Prisma client generator +### 2.2. Configure Prisma + +Create a `prisma.config.ts` file in the root of your project with the following content: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +The `dotenv` package should already be installed as it's a Next.js dependency. If not, install it using: + +```bash +npm install dotenv +``` + +::: + +### 2.3. Generate the Prisma client Run the following command to create the database tables and generate the Prisma Client: @@ -96,7 +125,7 @@ Run the following command to create the database tables and generate the Prisma npx prisma generate ``` -### 2.3. Set up a global Prisma client +### 2.4. Set up a global Prisma client Create a `/lib` directory and a `prisma.ts` file inside it. This file will be used to create and export your Prisma Client instance. @@ -325,8 +354,6 @@ With the new models in your schema, you need to update your database. Run a migr npx prisma migrate dev --name add-auth-models ``` -
- ## 4. Set up the API routes Better-Auth needs an API endpoint to handle authentication requests like sign-in, sign-up, and sign-out. You'll create a catch-all API route in Next.js to handle all requests sent to `/api/auth/[...all]`. diff --git a/content/800-guides/300-supabase-accelerate.mdx b/content/800-guides/300-supabase-accelerate.mdx index a898071628..75be0a3b5b 100644 --- a/content/800-guides/300-supabase-accelerate.mdx +++ b/content/800-guides/300-supabase-accelerate.mdx @@ -46,6 +46,33 @@ Update the file and set the `DATABASE_URL` to your Supabase connection string: DATABASE_URL="postgresql://postgres:[YOUR-PASSWORD]@db.nzpppscrldfwlzfalbrf.supabase.co:5432/postgres" ``` +Create a `prisma.config.ts` file to configure Prisma: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables: + +```bash +npm install dotenv +``` + +::: + ## 2. Introspect your database Next, run the following command to introspect your database and create your data model: @@ -58,7 +85,7 @@ This command reads your database schema and creates new models in your `schema.p :::note -If you want to use Prisma Migrate in the future, you also need to [baseline your database](/orm/prisma-migrate/workflows/baselining). +If you want to use Prisma Migrate in the future, you also need to [baseline your database](/orm/prisma-migrate/workflows/baselining). ::: diff --git a/content/800-guides/310-neon-accelerate.mdx b/content/800-guides/310-neon-accelerate.mdx index 95d3b1987c..2d0fe65d68 100644 --- a/content/800-guides/310-neon-accelerate.mdx +++ b/content/800-guides/310-neon-accelerate.mdx @@ -46,6 +46,33 @@ Update the file and set the `DATABASE_URL` to your Neon connection string: DATABASE_URL="postgresql://neondb_owner:[YOUR-PASSWORD]@ep-lingering-hat-a2e7tkt3.eu-central-1.aws.neon.tech/neondb?sslmode=require" ``` +Create a `prisma.config.ts` file to configure Prisma: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables: + +```bash +npm install dotenv +``` + +::: + ## 2. Introspect your database Next, run the following command to introspect your database and create your data model: @@ -58,7 +85,7 @@ This command reads your database schema and creates new models in your `schema.p :::note -If you want to use Prisma Migrate in the future, you also need to [baseline your database](/orm/prisma-migrate/workflows/baselining). +If you want to use Prisma Migrate in the future, you also need to [baseline your database](/orm/prisma-migrate/workflows/baselining). ::: diff --git a/content/800-guides/320-permit-io-access-control.mdx b/content/800-guides/320-permit-io-access-control.mdx index 39e3e7f688..8e06c85951 100644 --- a/content/800-guides/320-permit-io-access-control.mdx +++ b/content/800-guides/320-permit-io-access-control.mdx @@ -211,7 +211,6 @@ export default defineConfig({ migrations: { path: 'prisma/migrations', }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, diff --git a/content/800-guides/330-github-actions.mdx b/content/800-guides/330-github-actions.mdx index b89d46545b..09b54542cd 100644 --- a/content/800-guides/330-github-actions.mdx +++ b/content/800-guides/330-github-actions.mdx @@ -97,6 +97,36 @@ model Post { } ``` +Create a `prisma.config.ts` file to configure Prisma with seeding: + +```typescript file=prisma.config.ts +//add-start +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + seed: `tsx src/seed.ts`, + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +//add-end +``` + +:::note + +You'll need to install the `dotenv` package: + +```terminal +npm install dotenv +``` + +::: + ### 2.3. Run initial migration and generate client ```terminal diff --git a/content/800-guides/340-ai-sdk-nextjs.mdx b/content/800-guides/340-ai-sdk-nextjs.mdx index d59d18004d..7043e1c8ae 100644 --- a/content/800-guides/340-ai-sdk-nextjs.mdx +++ b/content/800-guides/340-ai-sdk-nextjs.mdx @@ -140,7 +140,6 @@ export default defineConfig({ migrations: { path: 'prisma/migrations', }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, diff --git a/content/800-guides/350-authjs-nextjs.mdx b/content/800-guides/350-authjs-nextjs.mdx index 2bf14e647b..e4e00f9740 100644 --- a/content/800-guides/350-authjs-nextjs.mdx +++ b/content/800-guides/350-authjs-nextjs.mdx @@ -187,7 +187,6 @@ export default defineConfig({ migrations: { path: 'prisma/migrations', }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, diff --git a/content/800-guides/360-embed-studio-nextjs.mdx b/content/800-guides/360-embed-studio-nextjs.mdx index 2b117d1664..9394baffeb 100644 --- a/content/800-guides/360-embed-studio-nextjs.mdx +++ b/content/800-guides/360-embed-studio-nextjs.mdx @@ -157,7 +157,6 @@ export default defineConfig({ migrations: { path: 'prisma/migrations', }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, @@ -243,7 +242,6 @@ export default defineConfig({ path: 'prisma/migrations', seed: `tsx prisma/seed.ts`, }, - engine: 'classic', datasource: { url: env('DIRECT_URL'), }, diff --git a/content/800-guides/370-bun.mdx b/content/800-guides/370-bun.mdx index fd90ceac90..a950df07f9 100644 --- a/content/800-guides/370-bun.mdx +++ b/content/800-guides/370-bun.mdx @@ -169,16 +169,17 @@ main() Add the following content to the file: ```typescript file=prisma.config.ts +import 'dotenv/config' import { defineConfig, env } from 'prisma/config'; + export default defineConfig({ schema: 'prisma/schema.prisma', - migrations: { - path: 'prisma/migrations', + migrations: { + path: 'prisma/migrations', // add-start - seed: `bun run prisma/seed.ts` + seed: `bun run prisma/seed.ts` //add-end }, - engine: 'classic', datasource: { url: env('DATABASE_URL'), }, diff --git a/content/800-guides/390-hono.mdx b/content/800-guides/390-hono.mdx index 40df95a5b9..6468eacaaf 100644 --- a/content/800-guides/390-hono.mdx +++ b/content/800-guides/390-hono.mdx @@ -106,17 +106,17 @@ This creates two models: `User` and `Post`, with a one-to-many relationship betw In `prisma.config.ts`, import `dotenv` at the top of the file -```ts +```typescript file=prisma.config.ts import { defineConfig, env } from "prisma/config"; // add-start import "dotenv/config"; // add-end + export default defineConfig({ schema: "prisma/schema.prisma", migrations: { path: "prisma/migrations", }, - engine: "classic", datasource: { url: env("DATABASE_URL"), }, @@ -192,9 +192,10 @@ main() Now, tell Prisma how to run this script by updating your `prisma.config.ts`: -```ts file=prisma.config.ts +```typescript file=prisma.config.ts import { defineConfig, env } from "prisma/config"; import "dotenv/config"; + export default defineConfig({ schema: "prisma/schema.prisma", migrations: { @@ -203,7 +204,6 @@ export default defineConfig({ seed: "tsx prisma/seed.ts" //add-end }, - engine: "classic", datasource: { url: env("DATABASE_URL"), }, diff --git a/content/800-guides/999-making-guides.mdx b/content/800-guides/999-making-guides.mdx index b8d2a04f8f..8186c8145c 100644 --- a/content/800-guides/999-making-guides.mdx +++ b/content/800-guides/999-making-guides.mdx @@ -344,14 +344,47 @@ model Post { This creates two models: `User` and `Post`, with a one-to-many relationship between them. -### 2.3. Configure the Prisma Client generator +### 2.3. Configure Prisma + +Create a `prisma.config.ts` file in the root of your project with the following content: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); +``` + +:::note + +You'll need to install the `dotenv` package to load environment variables: + +```bash +npm install dotenv +``` + +::: + +:::warning +***DEV NOTE:*** If your guide includes database seeding, you'll update this config file later to add the `seed` field in the migrations section. See the seeding section below for an example. +::: + +### 2.4. Generate Prisma Client and run migrations Now, run the following command to create the database tables and generate the Prisma Client: ```terminal npx prisma migrate dev --name init ``` -### 2.4. Seed the database +### 2.5. Seed the database Add some seed data to populate the database with sample users and posts. @@ -404,16 +437,24 @@ export async function main() { main(); ``` -Now, tell Prisma how to run this script by updating your `package.json`: +Create a `prisma.config.ts` file to configure Prisma with seeding: -```json file=package.json -... rest of the file +```typescript file=prisma.config.ts //add-start -"prisma": { - "seed": "tsx prisma/seed.ts" -} +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + seed: `tsx prisma/seed.ts`, + }, + datasource: { + url: env('DATABASE_URL'), + }, +}); //add-end -... rest of the file ``` Run the seed script: From c9011175b94a1727ab377ce580ebc3a127cac958 Mon Sep 17 00:00:00 2001 From: Nurul Sundarani Date: Fri, 14 Nov 2025 19:28:57 +0530 Subject: [PATCH 2/2] refactor: Updated guides for Prisma 7 changes --- content/800-guides/010-data-migration.mdx | 16 ++++++-- .../800-guides/040-migrate-from-sequelize.mdx | 4 +- .../800-guides/060-migrate-from-drizzle.mdx | 20 ++++++---- content/800-guides/070-cloudflare-d1.mdx | 3 +- content/800-guides/080-turborepo.mdx | 14 +++++-- content/800-guides/090-nextjs.mdx | 33 ++++++++++++----- content/800-guides/100-nuxt.mdx | 4 +- content/800-guides/130-docker.mdx | 12 ++++-- .../140-use-prisma-in-pnpm-workspaces.mdx | 14 +++---- content/800-guides/150-multiple-databases.mdx | 37 ++++++------------- content/800-guides/160-tanstack-start.mdx | 25 ++++++++++--- content/800-guides/170-react-router-7.mdx | 27 +++++++++++--- content/800-guides/180-solid-start.mdx | 25 ++++++++++--- content/800-guides/190-data-dog.mdx | 3 +- content/800-guides/190-sveltekit.mdx | 21 ++++++++--- content/800-guides/200-clerk-nextjs.mdx | 14 +++++-- content/800-guides/220-astro.mdx | 21 ++++++++--- content/800-guides/230-betterauth-nextjs.mdx | 15 ++++++-- .../800-guides/300-supabase-accelerate.mdx | 36 +++++++++++++----- content/800-guides/310-neon-accelerate.mdx | 36 +++++++++++++----- .../320-permit-io-access-control.mdx | 21 +++++++++-- content/800-guides/330-github-actions.mdx | 5 ++- content/800-guides/340-ai-sdk-nextjs.mdx | 18 ++++++--- content/800-guides/350-authjs-nextjs.mdx | 18 ++++++--- .../800-guides/360-embed-studio-nextjs.mdx | 12 ++++-- content/800-guides/370-bun.mdx | 21 +++++++++-- content/800-guides/390-hono.mdx | 22 ++++++++--- content/800-guides/400-deno-integration.mdx | 1 - content/800-guides/999-making-guides.mdx | 22 +++++++++-- 29 files changed, 364 insertions(+), 156 deletions(-) diff --git a/content/800-guides/010-data-migration.mdx b/content/800-guides/010-data-migration.mdx index 9f8893c69c..81e58874e3 100644 --- a/content/800-guides/010-data-migration.mdx +++ b/content/800-guides/010-data-migration.mdx @@ -45,12 +45,12 @@ Start with a basic schema containing a Post model: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated/prisma" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model Post { @@ -137,9 +137,17 @@ npx prisma migrate dev --name add-status-column Create a new TypeScript file for the data migration: ```typescript -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../generated/prisma/client' +import { PrismaPg } from '@prisma/adapter-pg' +import 'dotenv/config' + +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL, +}) -const prisma = new PrismaClient() +const prisma = new PrismaClient({ + adapter, +}) async function main() { await prisma.$transaction(async (tx) => { diff --git a/content/800-guides/040-migrate-from-sequelize.mdx b/content/800-guides/040-migrate-from-sequelize.mdx index bc98456af4..663f59366a 100644 --- a/content/800-guides/040-migrate-from-sequelize.mdx +++ b/content/800-guides/040-migrate-from-sequelize.mdx @@ -58,11 +58,11 @@ The Prisma schema currently looks as follows: datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated/prisma" } ``` diff --git a/content/800-guides/060-migrate-from-drizzle.mdx b/content/800-guides/060-migrate-from-drizzle.mdx index 0fe8942aca..0b53916367 100644 --- a/content/800-guides/060-migrate-from-drizzle.mdx +++ b/content/800-guides/060-migrate-from-drizzle.mdx @@ -82,11 +82,11 @@ The Prisma schema currently looks as follows: datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated/prisma" } ``` @@ -107,7 +107,6 @@ If you're not using PostgreSQL, you need to adjust the `provider` field on the ` ```prisma file=schema.prisma showLineNumbers datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` @@ -118,7 +117,6 @@ datasource db { ```prisma file=schema.prisma showLineNumbers datasource db { provider = "mysql" - url = env("DATABASE_URL") } ``` @@ -129,7 +127,6 @@ datasource db { ```prisma file=schema.prisma showLineNumbers datasource db { provider = "sqlserver" - url = env("DATABASE_URL") } ``` @@ -140,7 +137,6 @@ datasource db { ```prisma file=schema.prisma showLineNumbers datasource db { provider = "sqlite" - url = env("DATABASE_URL") } ``` @@ -283,9 +279,17 @@ touch db/prisma.ts Now, instantiate `PrismaClient` and export it from the file so you can use it in your route handlers later: ```ts copy file=db/prisma.ts showLineNumbers -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../generated/prisma/client' +import { PrismaPg } from '@prisma/adapter-pg' +import 'dotenv/config' + +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL, +}) -export const prisma = new PrismaClient() +export const prisma = new PrismaClient({ + adapter, +}) ``` ### 4.1. Replacing `getData` queries diff --git a/content/800-guides/070-cloudflare-d1.mdx b/content/800-guides/070-cloudflare-d1.mdx index 9dbb973915..fc714c1428 100644 --- a/content/800-guides/070-cloudflare-d1.mdx +++ b/content/800-guides/070-cloudflare-d1.mdx @@ -53,13 +53,12 @@ In your Prisma schema, set the `provider` of the `datasource` to `sqlite`. If yo ```prisma file=prisma/schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "../src/generated/prisma" } datasource db { provider = "sqlite" - url = env("DATABASE_URL") } //add-start diff --git a/content/800-guides/080-turborepo.mdx b/content/800-guides/080-turborepo.mdx index f0dd46e806..c39d302495 100644 --- a/content/800-guides/080-turborepo.mdx +++ b/content/800-guides/080-turborepo.mdx @@ -200,7 +200,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -400,7 +399,9 @@ import { withAccelerate } from "@prisma/extension-accelerate"; const globalForPrisma = global as unknown as { prisma: PrismaClient }; export const prisma = - globalForPrisma.prisma || new PrismaClient().$extends(withAccelerate()); + globalForPrisma.prisma || new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, + }).$extends(withAccelerate()); if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; ``` @@ -411,11 +412,18 @@ if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; ```ts file=packages/database/src/client.ts import { PrismaClient } from "../generated/prisma"; +import { PrismaPg } from '@prisma/adapter-pg'; + +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL, +}); const globalForPrisma = global as unknown as { prisma: PrismaClient }; export const prisma = - globalForPrisma.prisma || new PrismaClient(); + globalForPrisma.prisma || new PrismaClient({ + adapter, + }); if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; ``` diff --git a/content/800-guides/090-nextjs.mdx b/content/800-guides/090-nextjs.mdx index 1b55438503..d5e242f4ac 100644 --- a/content/800-guides/090-nextjs.mdx +++ b/content/800-guides/090-nextjs.mdx @@ -110,7 +110,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -171,8 +170,16 @@ Create a new file called `seed.ts` in the `prisma/` directory: ```typescript file=prisma/seed.ts import { PrismaClient, Prisma } from "../app/generated/prisma"; +import { PrismaPg } from '@prisma/adapter-pg' +import 'dotenv/config' + +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL, +}) -const prisma = new PrismaClient(); +const prisma = new PrismaClient({ + adapter, +}); const userData: Prisma.UserCreateInput[] = [ { @@ -287,11 +294,13 @@ Now, add the following code to your `lib/prisma.ts` file: import { PrismaClient } from '../app/generated/prisma' import { withAccelerate } from '@prisma/extension-accelerate' -const globalForPrisma = global as unknown as { +const globalForPrisma = global as unknown as { prisma: PrismaClient } -const prisma = globalForPrisma.prisma || new PrismaClient().$extends(withAccelerate()) +const prisma = globalForPrisma.prisma || new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, +}).$extends(withAccelerate()) if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma @@ -304,12 +313,19 @@ export default prisma ```typescript file=lib/prisma.ts showLineNumbers //add-start import { PrismaClient } from '../src/app/generated/prisma' +import { PrismaPg } from '@prisma/adapter-pg' -const globalForPrisma = global as unknown as { +const globalForPrisma = global as unknown as { prisma: PrismaClient } -const prisma = globalForPrisma.prisma || new PrismaClient() +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL, +}) + +const prisma = globalForPrisma.prisma || new PrismaClient({ + adapter, +}) if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma @@ -683,7 +699,7 @@ Before you deploy, you also need to tell Vercel to make sure that the Prisma Cli "scripts": { "dev": "next dev --turbopack", "build": "next build", - "postinstall": "prisma generate --no-engine", + "postinstall": "prisma generate", "start": "next start", "lint": "next lint" }, @@ -713,9 +729,6 @@ Before you deploy, you also need to tell Vercel to make sure that the Prisma Cli } ``` -:::note -If you're not using Prisma Postgres, you need to remove the `--no-engine` flag from the command. -::: After this change, you can deploy your application to Vercel by running `vercel`. diff --git a/content/800-guides/100-nuxt.mdx b/content/800-guides/100-nuxt.mdx index 11aa72da40..58cee219c7 100644 --- a/content/800-guides/100-nuxt.mdx +++ b/content/800-guides/100-nuxt.mdx @@ -119,12 +119,11 @@ Once the setup flow has terminated, it: // learn more about it in the docs: https://pris.ly/d/prisma-schema generator client { - provider = "prisma-client-js" + provider = "prisma-client" } datasource db { provider = "sqlite" - url = env("DATABASE_URL") } model User { @@ -239,7 +238,6 @@ Now that the Prisma Postgres instance is ready, update your Nuxt application to datasource db { // edit-next-line provider = "postgresql" - url = env("DATABASE_URL") } ``` 3. Delete the SQLite database files (`dev.db` and `dev.db-journal`) along with the `migrations` folder, all located in the `prisma` directory. This cleans up the existing SQLite setup and prepares your project to migrate to PostgreSQL. diff --git a/content/800-guides/130-docker.mdx b/content/800-guides/130-docker.mdx index c8c24a5838..031b660565 100644 --- a/content/800-guides/130-docker.mdx +++ b/content/800-guides/130-docker.mdx @@ -100,11 +100,10 @@ Add a `User` model to the `schema.prisma` file located in the `prisma/schema.pri ```prisma file=prisma/schema.prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" //add-start output = "../generated/prisma_client" //add-end @@ -167,9 +166,16 @@ Add the following code to set up a basic Express server: //add-start const express = require("express"); const { PrismaClient } = require("./generated/prisma_client"); +const { PrismaPg } = require("@prisma/adapter-pg"); + +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL, +}); const app = express(); -const prisma = new PrismaClient(); +const prisma = new PrismaClient({ + adapter, +}); app.use(express.json()); // Get all users diff --git a/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx b/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx index 45757bd01a..82bf8a72c7 100644 --- a/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx +++ b/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx @@ -141,7 +141,7 @@ Edit the `schema.prisma` file to define a `User` model in your database and spec ```prisma file=prisma/schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" //add-start output = "../generated/client" //add-end @@ -149,7 +149,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -199,7 +198,7 @@ Next, add helper scripts to your `package.json` to simplify Prisma commands: "test": "echo \"Error: no test specified\" && exit 1", // delete-end // add-start - "db:generate": "prisma generate --no-engine", + "db:generate": "prisma generate", "db:migrate": "prisma migrate dev", "db:deploy": "prisma migrate deploy", "db:studio": "prisma studio" @@ -208,11 +207,6 @@ Next, add helper scripts to your `package.json` to simplify Prisma commands: } ``` -:::info - -If you're not using [Prisma Postgres](/postgres/introduction/getting-started) for your database, exclude the `--no-engine` flag from the `db:generate` script. - -::: Use [Prisma Migrate](/orm/prisma-migrate) to migrate your database changes: @@ -230,7 +224,9 @@ import { PrismaClient } from "./generated/client"; import { withAccelerate } from "@prisma/extension-accelerate"; // Instantiate the extended Prisma client to infer its type -const extendedPrisma = new PrismaClient().$extends(withAccelerate()); +const extendedPrisma = new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, +}).$extends(withAccelerate()); type ExtendedPrismaClient = typeof extendedPrisma; // Use globalThis for broader environment compatibility diff --git a/content/800-guides/150-multiple-databases.mdx b/content/800-guides/150-multiple-databases.mdx index f304134f9c..854b33908c 100644 --- a/content/800-guides/150-multiple-databases.mdx +++ b/content/800-guides/150-multiple-databases.mdx @@ -121,7 +121,7 @@ Open `prisma-user-database/schema.prisma` file and update it to define a `User` ```prisma file=prisma-user-database/schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" //add-start output = "../prisma-user-database/user-database-client-types" //add-end @@ -129,12 +129,6 @@ generator client { datasource db { provider = "postgresql" - //delete-start - url = env("DATABASE_URL") - //delete-end - //add-start - url = env("PPG_USER_DATABASE_URL") - //add-end } //add-start @@ -207,7 +201,7 @@ Edit the `prisma-post-database/schema.prisma` file to define a `Post` model. Als ```prisma file=prisma-post-database/schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" //add-start output = "../prisma-post-database/post-database-client-types" //add-end @@ -215,12 +209,6 @@ generator client { datasource db { provider = "postgresql" - //delete-start - url = env("DATABASE_URL") - //delete-end - //add-start - url = env("PPG_POST_DATABASE_URL") - //add-end } //add-start @@ -264,8 +252,8 @@ To simplify your workflow, add helper scripts to your `package.json` file that r "start": "next start", "lint": "next lint", // add-start - "postinstall": "npx prisma generate --schema ./prisma-user-database/schema.prisma --no-engine && npx prisma generate --schema ./prisma-post-database/schema.prisma --no-engine", - "generate": "npx prisma generate --schema ./prisma-user-database/schema.prisma --no-engine && npx prisma generate --schema ./prisma-post-database/schema.prisma --no-engine", + "postinstall": "npx prisma generate --schema ./prisma-user-database/schema.prisma && npx prisma generate --schema ./prisma-post-database/schema.prisma", + "generate": "npx prisma generate --schema ./prisma-user-database/schema.prisma && npx prisma generate --schema ./prisma-post-database/schema.prisma", "migrate": "npx prisma migrate dev --schema ./prisma-user-database/schema.prisma && npx prisma migrate dev --schema ./prisma-post-database/schema.prisma", "deploy": "npx prisma migrate deploy --schema ./prisma-user-database/schema.prisma && npx prisma migrate deploy --schema ./prisma-post-database/schema.prisma", "studio": "npx prisma studio --schema ./prisma-user-database/schema.prisma --port 5555 & npx prisma studio --schema ./prisma-post-database/schema.prisma --port 5556" @@ -273,11 +261,6 @@ To simplify your workflow, add helper scripts to your `package.json` file that r } ``` -:::info - -If you are not using a Prisma Postgres database, remove the `--no-engine` flag from the custom scripts above. - -::: Here is an explanation of the custom scripts: @@ -312,7 +295,9 @@ In `lib/user-prisma-client.ts`, add the following code: import { PrismaClient } from "../prisma-user-database/user-database-client-types"; import { withAccelerate } from "@prisma/extension-accelerate" -const getPrisma = () => new PrismaClient().$extends(withAccelerate()); +const getPrisma = () => new PrismaClient({ + accelerateUrl: process.env.PPG_USER_DATABASE_URL, +}).$extends(withAccelerate()); const globalForUserDBPrismaClient = global as unknown as { userDBPrismaClient: ReturnType; @@ -341,7 +326,9 @@ In `lib/post-prisma-client.ts`, add this code: import { PrismaClient } from "../prisma-post-database/post-database-client-types"; import { withAccelerate } from "@prisma/extension-accelerate" -const getPrisma = () => new PrismaClient().$extends(withAccelerate()); +const getPrisma = () => new PrismaClient({ + accelerateUrl: process.env.PPG_POST_DATABASE_URL, +}).$extends(withAccelerate()); const globalForPostDBPrismaClient = global as unknown as { postDBPrismaClient: ReturnType; @@ -433,8 +420,8 @@ Before starting the development server, note that if you are using Next.js `v15. "build": "next build", "start": "next start", "lint": "next lint", - "postinstall": "npx prisma generate --schema ./prisma-user-database/schema.prisma --no-engine && npx prisma generate --schema ./prisma-post-database/schema.prisma --no-engine", - "generate": "npx prisma generate --schema ./prisma-user-database/schema.prisma --no-engine && npx prisma generate --schema ./prisma-post-database/schema.prisma --no-engine", + "postinstall": "npx prisma generate --schema ./prisma-user-database/schema.prisma && npx prisma generate --schema ./prisma-post-database/schema.prisma", + "generate": "npx prisma generate --schema ./prisma-user-database/schema.prisma && npx prisma generate --schema ./prisma-post-database/schema.prisma", "migrate": "npx prisma migrate dev --schema ./prisma-user-database/schema.prisma && npx prisma migrate dev --schema ./prisma-post-database/schema.prisma", "deploy": "npx prisma migrate deploy --schema ./prisma-user-database/schema.prisma && npx prisma migrate deploy --schema ./prisma-post-database/schema.prisma", "studio": "npx prisma studio --schema ./prisma-user-database/schema.prisma --port 5555 & npx prisma studio --schema ./prisma-post-database/schema.prisma --port 5556" diff --git a/content/800-guides/160-tanstack-start.mdx b/content/800-guides/160-tanstack-start.mdx index a288dbd61b..85ce70c040 100644 --- a/content/800-guides/160-tanstack-start.mdx +++ b/content/800-guides/160-tanstack-start.mdx @@ -316,7 +316,7 @@ npm install @prisma/extension-accelerate @prisma/client dotenv ```terminal npm install prisma tsx --save-dev -npm install @prisma/client dotenv +npm install @prisma/client @prisma/adapter-pg dotenv ``` @@ -351,7 +351,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -411,8 +410,15 @@ Create a new file called `seed.ts` in the `prisma/` directory: ```typescript file=prisma/seed.ts import { PrismaClient, Prisma } from "../app/generated/prisma/client.js"; +import { PrismaPg } from "@prisma/adapter-pg"; -const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const prisma = new PrismaClient({ + adapter, +}); const userData: Prisma.UserCreateInput[] = [ { @@ -501,7 +507,9 @@ Set up the Prisma client like this: import { PrismaClient } from "../generated/prisma/client.js"; import { withAccelerate } from "@prisma/extension-accelerate"; -const prisma = new PrismaClient().$extends(withAccelerate()); +const prisma = new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, +}).$extends(withAccelerate()); export default prisma; ``` @@ -509,8 +517,15 @@ export default prisma; ```tsx file=src/lib/prisma.ts import { PrismaClient } from "../generated/prisma/client.js"; +import { PrismaPg } from "@prisma/adapter-pg"; -const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const prisma = new PrismaClient({ + adapter, +}); export default prisma; ``` diff --git a/content/800-guides/170-react-router-7.mdx b/content/800-guides/170-react-router-7.mdx index c953dd4990..7a8b96d633 100644 --- a/content/800-guides/170-react-router-7.mdx +++ b/content/800-guides/170-react-router-7.mdx @@ -56,7 +56,7 @@ npm install @prisma/extension-accelerate @prisma/client dotenv ```terminal npm install prisma tsx --save-dev -npm install @prisma/client dotenv +npm install @prisma/client @prisma/adapter-pg dotenv ``` @@ -90,7 +90,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -150,8 +149,15 @@ Create a new file called `seed.ts` in the `prisma/` directory: ```typescript file=prisma/seed.ts import { PrismaClient, Prisma } from "../app/generated/prisma/client.js"; +import { PrismaPg } from "@prisma/adapter-pg"; -const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const prisma = new PrismaClient({ + adapter, +}); const userData: Prisma.UserCreateInput[] = [ { @@ -244,7 +250,9 @@ const globalForPrisma = global as unknown as { prisma: PrismaClient } -const prisma = globalForPrisma.prisma || new PrismaClient().$extends(withAccelerate()) +const prisma = globalForPrisma.prisma || new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, +}).$extends(withAccelerate()) if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma @@ -255,12 +263,19 @@ export default prisma ```typescript file=app/lib/prisma.ts import { PrismaClient } from "../generated/prisma/client.js"; +import { PrismaPg } from "@prisma/adapter-pg"; -const globalForPrisma = global as unknown as { +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const globalForPrisma = global as unknown as { prisma: PrismaClient } -const prisma = globalForPrisma.prisma || new PrismaClient() +const prisma = globalForPrisma.prisma || new PrismaClient({ + adapter, +}) if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma diff --git a/content/800-guides/180-solid-start.mdx b/content/800-guides/180-solid-start.mdx index 85e99aeff7..4efe665593 100644 --- a/content/800-guides/180-solid-start.mdx +++ b/content/800-guides/180-solid-start.mdx @@ -76,7 +76,7 @@ npm install @prisma/extension-accelerate @prisma/client dotenv ```terminal npm install prisma tsx --save-dev -npm install @prisma/client dotenv +npm install @prisma/client @prisma/adapter-pg dotenv ``` @@ -110,7 +110,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -171,8 +170,15 @@ Create a new file called `seed.ts` in the `prisma/` directory: ```typescript file=prisma/seed.ts import { PrismaClient, Prisma } from "../src/generated/prisma/client.js"; +import { PrismaPg } from "@prisma/adapter-pg"; -const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const prisma = new PrismaClient({ + adapter, +}); const userData: Prisma.UserCreateInput[] = [ { @@ -265,7 +271,9 @@ Add the following code to create a Prisma Client instance: import { PrismaClient } from "../src/generated/prisma/client.js"; import { withAccelerate } from "@prisma/extension-accelerate"; -const prisma = new PrismaClient().$extends(withAccelerate()); +const prisma = new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, +}).$extends(withAccelerate()); export default prisma; ``` @@ -274,8 +282,15 @@ export default prisma; ```typescript file=lib/prisma.ts import { PrismaClient } from "../src/generated/prisma/client.js"; +import { PrismaPg } from "@prisma/adapter-pg"; -const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const prisma = new PrismaClient({ + adapter, +}); export default prisma; ``` diff --git a/content/800-guides/190-data-dog.mdx b/content/800-guides/190-data-dog.mdx index fcba863180..ef7b600aae 100644 --- a/content/800-guides/190-data-dog.mdx +++ b/content/800-guides/190-data-dog.mdx @@ -154,13 +154,12 @@ Now, open `prisma/schema.prisma` and update your generator block and models. Rep ```prisma file=prisma/schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "../src/generated/prisma" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start diff --git a/content/800-guides/190-sveltekit.mdx b/content/800-guides/190-sveltekit.mdx index 7625b273aa..eba7f3fefc 100644 --- a/content/800-guides/190-sveltekit.mdx +++ b/content/800-guides/190-sveltekit.mdx @@ -70,7 +70,7 @@ npm install @prisma/extension-accelerate @prisma/client dotenv ```terminal npm install prisma tsx --save-dev -npm install @prisma/client dotenv +npm install @prisma/client @prisma/adapter-pg dotenv ``` @@ -104,7 +104,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -164,8 +163,15 @@ Create a new file called `seed.ts` in the `prisma/` directory: ```typescript file=prisma/seed.ts import { PrismaClient, Prisma } from "../src/generated/prisma/client.js"; +import { PrismaPg } from "@prisma/adapter-pg"; -const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const prisma = new PrismaClient({ + adapter, +}); const userData: Prisma.UserCreateInput[] = [ { @@ -262,7 +268,7 @@ import { DATABASE_URL } from '$env/static/private'; import { withAccelerate } from '@prisma/extension-accelerate'; const prisma = new PrismaClient({ - datasourceUrl: DATABASE_URL + accelerateUrl: DATABASE_URL }).$extends(withAccelerate()); export default prisma; @@ -273,9 +279,14 @@ export default prisma; ```tsx file=src/lib/prisma.ts import { PrismaClient } from '../generated/prisma/client.js'; import { DATABASE_URL } from '$env/static/private'; +import { PrismaPg } from '@prisma/adapter-pg'; + +const adapter = new PrismaPg({ + connectionString: DATABASE_URL, +}); const prisma = new PrismaClient({ - datasourceUrl: DATABASE_URL + adapter, }); export default prisma; diff --git a/content/800-guides/200-clerk-nextjs.mdx b/content/800-guides/200-clerk-nextjs.mdx index e1fcfd2810..09e849de66 100644 --- a/content/800-guides/200-clerk-nextjs.mdx +++ b/content/800-guides/200-clerk-nextjs.mdx @@ -260,7 +260,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -343,7 +342,9 @@ const globalForPrisma = global as unknown as { }; const prisma = - globalForPrisma.prisma || new PrismaClient().$extends(withAccelerate()); + globalForPrisma.prisma || new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, +}).$extends(withAccelerate()); if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; @@ -355,12 +356,19 @@ export default prisma; ```tsx file=lib/prisma.ts showLineNumbers //add-start import { PrismaClient } from "../app/generated/prisma"; +import { PrismaPg } from "@prisma/adapter-pg"; + +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); const globalForPrisma = global as unknown as { prisma: PrismaClient; }; -const prisma = globalForPrisma.prisma || new PrismaClient(); +const prisma = globalForPrisma.prisma || new PrismaClient({ + adapter, +}); if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; diff --git a/content/800-guides/220-astro.mdx b/content/800-guides/220-astro.mdx index ad28d9a98c..beae2a5d44 100644 --- a/content/800-guides/220-astro.mdx +++ b/content/800-guides/220-astro.mdx @@ -59,7 +59,7 @@ npm install @prisma/extension-accelerate @prisma/client dotenv ```terminal npm install prisma tsx --save-dev -npm install @prisma/client dotenv +npm install @prisma/client @prisma/adapter-pg dotenv ``` @@ -90,7 +90,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -151,8 +150,15 @@ Create a new file called `seed.ts` in the `prisma/` directory: ```typescript file=prisma/seed.ts import { PrismaClient, Prisma } from "../prisma/generated/client.js"; +import { PrismaPg } from "@prisma/adapter-pg"; -const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const prisma = new PrismaClient({ + adapter, +}); const userData: Prisma.UserCreateInput[] = [ { @@ -274,7 +280,7 @@ import { PrismaClient } from "../../prisma/generated/client"; import { withAccelerate } from "@prisma/extension-accelerate"; const prisma = new PrismaClient({ - datasourceUrl: import.meta.env.DATABASE_URL, + accelerateUrl: import.meta.env.DATABASE_URL, }).$extends(withAccelerate()); export default prisma; @@ -284,9 +290,14 @@ export default prisma; ```typescript file=src/lib/prisma.ts import { PrismaClient } from "../../prisma/generated/client"; +import { PrismaPg } from "@prisma/adapter-pg"; + +const adapter = new PrismaPg({ + connectionString: import.meta.env.DATABASE_URL, +}); const prisma = new PrismaClient({ - datasourceUrl: import.meta.env.DATABASE_URL, + adapter, }); export default prisma; diff --git a/content/800-guides/230-betterauth-nextjs.mdx b/content/800-guides/230-betterauth-nextjs.mdx index 0f9f756363..a48a7d5cc4 100644 --- a/content/800-guides/230-betterauth-nextjs.mdx +++ b/content/800-guides/230-betterauth-nextjs.mdx @@ -67,7 +67,7 @@ npm install @prisma/extension-accelerate @prisma/client ```terminal npm install prisma --save-dev -npm install @prisma/client +npm install @prisma/client @prisma/adapter-pg ``` @@ -147,7 +147,9 @@ const globalForPrisma = global as unknown as { }; const prisma = - globalForPrisma.prisma || new PrismaClient().$extends(withAccelerate()); + globalForPrisma.prisma || new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, + }).$extends(withAccelerate()); if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; @@ -157,13 +159,20 @@ export default prisma; ```tsx file=src/lib/prisma.ts import { PrismaClient } from "@/generated/prisma"; +import { PrismaPg } from "@prisma/adapter-pg"; + +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); const globalForPrisma = global as unknown as { prisma: PrismaClient; }; const prisma = - globalForPrisma.prisma || new PrismaClient() + globalForPrisma.prisma || new PrismaClient({ + adapter, + }); if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; diff --git a/content/800-guides/300-supabase-accelerate.mdx b/content/800-guides/300-supabase-accelerate.mdx index 75be0a3b5b..e319fc9c35 100644 --- a/content/800-guides/300-supabase-accelerate.mdx +++ b/content/800-guides/300-supabase-accelerate.mdx @@ -122,16 +122,26 @@ DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=ey..." :::note -If you want to use Prisma Migrate with Prisma Accelerate, you can set the `directUrl` field on the `datasource` block: +If you want to use Prisma Migrate with Prisma Accelerate, you need to provide a direct database URL in your `prisma.config.ts` file. The Accelerate URL (starting with `prisma://`) is used for queries via PrismaClient, while the direct database URL is used for migrations. -```prisma file=schema.prisma -datasource db { - url = env("DATABASE_URL") // points to the connection pool for queries - directUrl = env("DIRECT_URL") // points to the database for migrations -} +Update your `prisma.config.ts`: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DIRECT_URL'), // Direct database URL for migrations + }, +}); ``` -Accordingly, you'll need to set the `DIRECT_URL` in your `.env` file: +And add the `DIRECT_URL` to your `.env` file: ```bash file=.env DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=ey..." @@ -145,10 +155,14 @@ DIRECT_URL="postgresql://postgres:[YOUR-PASSWORD]@db.nzpppscrldfwlzfalbrf.supaba With your Prisma schema in place, you can go ahead and generate Prisma Client: ``` -npx prisma generate --no-engine +npx prisma generate ``` -The `--no-engine` option is used to omit the [query engine](/orm/more/under-the-hood/engines) in the generated Prisma Client library. The query engine manages Prisma ORM's internal connection pool and is not needed when using Prisma Accelerate. +:::info + +In Prisma 7, the `--no-engine` flag is no longer required when using Prisma Accelerate. Previously, you would run `prisma generate --no-engine`, but now the standard `prisma generate` command works for all use cases. + +::: ## 6. Send queries through the connection pool @@ -158,7 +172,9 @@ In your application code, you now need to apply the Accelerate extension to your import { PrismaClient } from "./generated/prisma" import { withAccelerate } from "@prisma/extension-accelerate" -const prisma = new PrismaClient().$extends(withAccelerate()) +const prisma = new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, +}).$extends(withAccelerate()) ``` At this point, you can now start sending queries which will be routed through the connection pool to your database. \ No newline at end of file diff --git a/content/800-guides/310-neon-accelerate.mdx b/content/800-guides/310-neon-accelerate.mdx index 2d0fe65d68..f353b515ea 100644 --- a/content/800-guides/310-neon-accelerate.mdx +++ b/content/800-guides/310-neon-accelerate.mdx @@ -122,16 +122,26 @@ DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=ey..." :::note -If you want to use Prisma Migrate with Prisma Accelerate, you can set the `directUrl` field on the `datasource` block: +If you want to use Prisma Migrate with Prisma Accelerate, you need to provide a direct database URL in your `prisma.config.ts` file. The Accelerate URL (starting with `prisma://`) is used for queries via PrismaClient, while the direct database URL is used for migrations. -```prisma file=schema.prisma -datasource db { - url = env("DATABASE_URL") // points to the connection pool for queries - directUrl = env("DIRECT_URL") // points to the database for migrations -} +Update your `prisma.config.ts`: + +```typescript file=prisma.config.ts +import 'dotenv/config' +import { defineConfig, env } from 'prisma/config'; + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DIRECT_URL'), // Direct database URL for migrations + }, +}); ``` -Accordingly, you'll need to set the `DIRECT_URL` in your `.env` file: +And add the `DIRECT_URL` to your `.env` file: ```bash file=.env DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=ey..." @@ -145,10 +155,14 @@ DIRECT_URL="postgresql://neondb_owner:[YOUR-PASSWORD]@ep-lingering-hat-a2e7tkt3. With your Prisma schema in place, you can go ahead and generate Prisma Client: ``` -npx prisma generate --no-engine +npx prisma generate ``` -The `--no-engine` option is used to omit the [query engine](/orm/more/under-the-hood/engines) in the generated Prisma Client library. The query engine manages Prisma ORM's internal connection pool and is not needed when using Prisma Accelerate. +:::info + +In Prisma 7, the `--no-engine` flag is no longer required when using Prisma Accelerate. Previously, you would run `prisma generate --no-engine`, but now the standard `prisma generate` command works for all use cases. + +::: ## 6. Send queries through the connection pool @@ -158,7 +172,9 @@ In your application code, you now need to apply the Accelerate extension to your import { PrismaClient } from "./generated/prisma" import { withAccelerate } from "@prisma/extension-accelerate" -const prisma = new PrismaClient().$extends(withAccelerate()) +const prisma = new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, +}).$extends(withAccelerate()) ``` At this point, you can now start sending queries which will be routed through the connection pool to your database. \ No newline at end of file diff --git a/content/800-guides/320-permit-io-access-control.mdx b/content/800-guides/320-permit-io-access-control.mdx index 8e06c85951..5d13d0594c 100644 --- a/content/800-guides/320-permit-io-access-control.mdx +++ b/content/800-guides/320-permit-io-access-control.mdx @@ -47,7 +47,7 @@ npm init -y Install application and development dependencies: ```terminal -npm install express cors dotenv @prisma/client +npm install express cors dotenv @prisma/client @prisma/adapter-pg npm install -D prisma typescript tsx ``` @@ -174,7 +174,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model Project { @@ -252,8 +251,15 @@ Create a new file at `scripts/seed.ts` and add the following: ```ts import { PrismaClient } from '../src/generated/prisma/client'; +import { PrismaPg } from '@prisma/adapter-pg'; -const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const prisma = new PrismaClient({ + adapter, +}); async function main() { console.log('🌱 Seeding test data...'); @@ -454,11 +460,18 @@ Create a new file: `src/middleware/auth.middleware.ts` ```ts import { Request, Response, NextFunction } from 'express'; import { PrismaClient } from '../generated/prisma/client.js'; +import { PrismaPg } from '@prisma/adapter-pg'; import createPermitClientExtension from '@permitio/permit-prisma'; import { clientExtensionConfig } from '../config/permit-config'; +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + // Extend PrismaClient with Permit -const prisma = new PrismaClient().$extends( +const prisma = new PrismaClient({ + adapter, +}).$extends( createPermitClientExtension(clientExtensionConfig) ); diff --git a/content/800-guides/330-github-actions.mdx b/content/800-guides/330-github-actions.mdx index 09b54542cd..3eb898d7a6 100644 --- a/content/800-guides/330-github-actions.mdx +++ b/content/800-guides/330-github-actions.mdx @@ -77,7 +77,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model User { @@ -144,7 +143,9 @@ import { withAccelerate } from "@prisma/extension-accelerate"; import { PrismaClient } from "../src/generated/prisma/client"; import "dotenv/config"; -const prisma = new PrismaClient().$extends(withAccelerate()); +const prisma = new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, +}).$extends(withAccelerate()); const userData = [ { diff --git a/content/800-guides/340-ai-sdk-nextjs.mdx b/content/800-guides/340-ai-sdk-nextjs.mdx index 7043e1c8ae..4d00104062 100644 --- a/content/800-guides/340-ai-sdk-nextjs.mdx +++ b/content/800-guides/340-ai-sdk-nextjs.mdx @@ -62,7 +62,7 @@ npm install @prisma/extension-accelerate @prisma/client dotenv ```terminal npm install prisma tsx --save-dev -npm install @prisma/client dotenv +npm install @prisma/client @prisma/adapter-pg dotenv ``` @@ -90,13 +90,12 @@ In the `prisma/schema.prisma` file, add the following models: ```prisma file=prisma/schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "../app/generated/prisma" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -175,7 +174,9 @@ const globalForPrisma = global as unknown as { prisma: PrismaClient; }; -const prisma = globalForPrisma.prisma || new PrismaClient().$extends(withAccelerate()); +const prisma = globalForPrisma.prisma || new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, +}).$extends(withAccelerate()); if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; @@ -186,12 +187,19 @@ export default prisma; ```tsx file=lib/prisma.ts import { PrismaClient } from "../app/generated/prisma/client"; +import { PrismaPg } from "@prisma/adapter-pg"; + +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); const globalForPrisma = global as unknown as { prisma: PrismaClient; }; -const prisma = globalForPrisma.prisma || new PrismaClient(); +const prisma = globalForPrisma.prisma || new PrismaClient({ + adapter, +}); if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; diff --git a/content/800-guides/350-authjs-nextjs.mdx b/content/800-guides/350-authjs-nextjs.mdx index e4e00f9740..3ccf3160e7 100644 --- a/content/800-guides/350-authjs-nextjs.mdx +++ b/content/800-guides/350-authjs-nextjs.mdx @@ -63,7 +63,7 @@ npm install @prisma/extension-accelerate @prisma/client dotenv ```terminal npm install prisma tsx --save-dev -npm install @prisma/client dotenv +npm install @prisma/client @prisma/adapter-pg dotenv ``` @@ -100,7 +100,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` @@ -216,7 +215,9 @@ const globalForPrisma = global as unknown as { prisma: PrismaClient } -const prisma = globalForPrisma.prisma || new PrismaClient().$extends(withAccelerate()) +const prisma = globalForPrisma.prisma || new PrismaClient({ + accelerateUrl: process.env.DATABASE_URL, +}).$extends(withAccelerate()) if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma @@ -229,12 +230,19 @@ export default prisma ```typescript file=lib/prisma.ts showLineNumbers //add-start import { PrismaClient } from '../app/generated/prisma' +import { PrismaPg } from '@prisma/adapter-pg' -const globalForPrisma = global as unknown as { +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}) + +const globalForPrisma = global as unknown as { prisma: PrismaClient } -const prisma = globalForPrisma.prisma || new PrismaClient() +const prisma = globalForPrisma.prisma || new PrismaClient({ + adapter, +}) if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma diff --git a/content/800-guides/360-embed-studio-nextjs.mdx b/content/800-guides/360-embed-studio-nextjs.mdx index 9394baffeb..dc50f894fb 100644 --- a/content/800-guides/360-embed-studio-nextjs.mdx +++ b/content/800-guides/360-embed-studio-nextjs.mdx @@ -80,7 +80,7 @@ Install the required Prisma packages: ```terminal npm install prisma tsx --save-dev -npm install @prisma/extension-accelerate @prisma/client dotenv +npm install @prisma/extension-accelerate @prisma/client @prisma/adapter-pg dotenv ``` ### 2.2. Initialize Prisma with Prisma Postgres @@ -117,7 +117,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -180,8 +179,15 @@ Create a seed file to add some sample data. Create a `seed.ts` file in the `pris ```typescript file=prisma/seed.ts import { PrismaClient } from '../app/generated/prisma' +import { PrismaPg } from '@prisma/adapter-pg' -const prisma = new PrismaClient() +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}) + +const prisma = new PrismaClient({ + adapter, +}) async function main() { // Create users diff --git a/content/800-guides/370-bun.mdx b/content/800-guides/370-bun.mdx index a950df07f9..00fdfa1ad3 100644 --- a/content/800-guides/370-bun.mdx +++ b/content/800-guides/370-bun.mdx @@ -43,7 +43,7 @@ Install the required Prisma packages and other dependencies: ```terminal bun add -d prisma -bun add @prisma/client +bun add @prisma/client @prisma/adapter-pg ``` ### 2.2. Initialize Prisma ORM with Prisma Postgres @@ -100,7 +100,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -120,8 +119,15 @@ Create a `db.ts` file in your project root to configure `PrismaClient`: ```typescript file=db.ts import { PrismaClient } from "./generated/prisma/client"; +import { PrismaPg } from "@prisma/adapter-pg"; -export const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +export const prisma = new PrismaClient({ + adapter, +}); ``` ### 3.2. Create a seed script @@ -130,8 +136,15 @@ Create a seed script in the `prisma` folder to populate your database with sampl ```typescript file=prisma/seed.ts import { PrismaClient } from "../generated/prisma/client"; +import { PrismaPg } from "@prisma/adapter-pg"; -const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const prisma = new PrismaClient({ + adapter, +}); async function main() { // Create multiple users diff --git a/content/800-guides/390-hono.mdx b/content/800-guides/390-hono.mdx index 6468eacaaf..f87d00968c 100644 --- a/content/800-guides/390-hono.mdx +++ b/content/800-guides/390-hono.mdx @@ -48,7 +48,7 @@ npm install @prisma/extension-accelerate @prisma/client dotenv ```terminal npm install prisma --save-dev -npm install @prisma/client dotenv +npm install @prisma/client @prisma/adapter-pg dotenv ``` @@ -80,7 +80,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -138,8 +137,15 @@ Create a new file called `seed.ts` in the `prisma/` directory: ```typescript file=prisma/seed.ts import { PrismaClient, Prisma } from "../src/generated/prisma/client.js"; +import { PrismaPg } from "@prisma/adapter-pg"; -const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const prisma = new PrismaClient({ + adapter, +}); const userData: Prisma.UserCreateInput[] = [ { @@ -244,7 +250,7 @@ function withPrisma(c: Context, next: Next) { if (!databaseUrl) { throw new Error('DATABASE_URL is not set'); } - const prisma = new PrismaClient({ datasourceUrl: databaseUrl }) + const prisma = new PrismaClient({ accelerateUrl: databaseUrl }) .$extends(withAccelerate()); c.set('prisma', prisma); @@ -261,13 +267,19 @@ export default withPrisma; ```tsx file=src/lib/prisma.ts import type { Context, Next } from 'hono'; import { PrismaClient } from '../generated/prisma/client.js'; +import { PrismaPg } from '@prisma/adapter-pg'; import "dotenv/config"; const databaseUrl = process.env.DATABASE_URL; if (!databaseUrl) { throw new Error('DATABASE_URL is not set'); } -const prisma = new PrismaClient({ datasourceUrl: databaseUrl }); + +const adapter = new PrismaPg({ + connectionString: databaseUrl, +}); + +const prisma = new PrismaClient({ adapter }); function withPrisma(c: Context, next: Next) { if (!c.get('prisma')) { diff --git a/content/800-guides/400-deno-integration.mdx b/content/800-guides/400-deno-integration.mdx index b0b10fe407..f6c7c8cefe 100644 --- a/content/800-guides/400-deno-integration.mdx +++ b/content/800-guides/400-deno-integration.mdx @@ -132,7 +132,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } // add-start diff --git a/content/800-guides/999-making-guides.mdx b/content/800-guides/999-making-guides.mdx index 8186c8145c..49ee775e9f 100644 --- a/content/800-guides/999-making-guides.mdx +++ b/content/800-guides/999-making-guides.mdx @@ -94,9 +94,17 @@ Example: ```typescript file=src/index.ts // Import required dependencies import { PrismaClient } from '@prisma/client' +import { PrismaPg } from '@prisma/adapter-pg' + +// Initialize adapter +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}) // Initialize Prisma Client -const prisma = new PrismaClient() +const prisma = new PrismaClient({ + adapter, +}) ``` ### Formatting conventions @@ -314,13 +322,12 @@ In addition, update the text above this and add "*and change the generator to us ```prisma file=prisma/schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "../generated/prisma" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -392,8 +399,15 @@ Create a new file called `seed.ts` in the `prisma/` directory: ```typescript file=prisma/seed.ts import { PrismaClient, Prisma } from "../generated/prisma"; +import { PrismaPg } from "@prisma/adapter-pg"; -const prisma = new PrismaClient(); +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); + +const prisma = new PrismaClient({ + adapter, +}); const userData: Prisma.UserCreateInput[] = [ {