Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions content/800-guides/010-data-migration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,19 @@ export default defineConfig({

:::note

You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager:
You'll need to install the required packages. If you haven't already, install them using your package manager:

```bash
npm install dotenv
npm install prisma @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg pg dotenv
```

:::info

If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).

:::

:::

### 1.3. Create a development branch
Expand Down
6 changes: 6 additions & 0 deletions content/800-guides/050-migrate-from-mongoose.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ This guide shows you how to migrate your application from Mongoose to Prisma ORM

You can learn how Prisma ORM compares to Mongoose on the [Prisma ORM vs Mongoose](/orm/more/comparisons/prisma-and-mongoose) page.

:::warning

This guide currently assumes you are using **Prisma ORM v6**. Support for Prisma ORM v7 with MongoDB is in progress.

:::

## Prerequisites

Before starting this guide, make sure you have:
Expand Down
19 changes: 10 additions & 9 deletions content/800-guides/060-migrate-from-drizzle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ Prisma ORM lends itself really well for **incremental adoption**. This means, yo
The first step to adopt Prisma ORM is to [install the Prisma CLI](/orm/tools/prisma-cli#installation) in your project:

```terminal copy
npm install prisma --save-dev && npm install @prisma/client
npm install prisma @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg pg
```

:::info

If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).

:::

## Step 2. Introspect your database

### 2.1. Set up Prisma ORM
Expand Down Expand Up @@ -252,15 +259,9 @@ model Todo {
}
```

## Step 3. Install and generate Prisma Client

As a next step, you can install Prisma Client in your project so that you can start replacing the database queries in your project that are currently made with Drizzle:

```terminal
npm install @prisma/client
```
## Step 3. Generate Prisma Client

After installing, you need to run `generate` in order to have your schema reflected in TypeScript types and autocomplete.
Now that you have installed Prisma Client in Step 1, you need to run `generate` in order to have your schema reflected in TypeScript types and autocomplete.

```terminal
npx prisma generate
Expand Down
66 changes: 8 additions & 58 deletions content/800-guides/080-turborepo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,60 +93,34 @@ Next, install the required dependencies to use Prisma ORM. Use your preferred pa
<TabItem value="npm">

```terminal
npm install prisma --save-dev
npm install @prisma/client dotenv
npm install prisma @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg dotenv pg
```

</TabItem>

<TabItem value="yarn">

```terminal
yarn add prisma --dev
yarn add @prisma/client dotenv
yarn add prisma @types/pg --dev
yarn add @prisma/client @prisma/adapter-pg dotenv pg
```

</TabItem>

<TabItem value="pnpm">

```terminal
pnpm add prisma --save-dev
pnpm add @prisma/client dotenv
pnpm add prisma @types/pg --save-dev
pnpm add @prisma/client @prisma/adapter-pg dotenv pg
```

</TabItem>
</TabbedContent>

:::note

If using [Prisma Postgres](https://prisma.io/postgres), install the `@prisma/extension-accelerate` package:

<TabbedContent code groupId="packageManager">
<TabItem value="npm">

```terminal
npm install @prisma/extension-accelerate
```

</TabItem>

<TabItem value="yarn">

```terminal
yarn add @prisma/extension-accelerate
```

</TabItem>

<TabItem value="pnpm">

```terminal
pnpm add @prisma/extension-accelerate
```
:::info

</TabItem>
</TabbedContent>
If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).

:::

Expand Down Expand Up @@ -389,27 +363,6 @@ Next, export the generated types and an instance of `PrismaClient` so it can use

In the `packages/database` directory, create a `src` folder and add a `client.ts` file. This file will define an instance of `PrismaClient`:

<TabbedContent code>
<TabItem value="Prisma Postgres (recommended)">

```ts file=packages/database/src/client.ts
import { PrismaClient } from "../generated/prisma";
import { withAccelerate } from "@prisma/extension-accelerate";

const globalForPrisma = global as unknown as { prisma: PrismaClient };

export const prisma =
globalForPrisma.prisma || new PrismaClient({
accelerateUrl: process.env.DATABASE_URL,
}).$extends(withAccelerate());

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
```

</TabItem>

<TabItem value="Other databases">

```ts file=packages/database/src/client.ts
import { PrismaClient } from "../generated/prisma";
import { PrismaPg } from '@prisma/adapter-pg';
Expand All @@ -428,9 +381,6 @@ export const prisma =
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
```

</TabItem>
</TabbedContent>

Then create an `index.ts` file in the `src` folder to re-export the generated prisma types and the `PrismaClient` instance:

```ts file=packages/database/src/index.ts
Expand Down
48 changes: 10 additions & 38 deletions content/800-guides/090-nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,16 @@ cd nextjs-prisma

To get started with Prisma, you'll need to install a few dependencies:

<TabbedContent code>
<TabItem value="Prisma Postgres (recommended)">
```terminal
npm install prisma tsx --save-dev
npm install @prisma/extension-accelerate @prisma/client dotenv
npm install prisma tsx @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg dotenv pg
```
</TabItem>
<TabItem value="Other databases">
```terminal
npm install prisma tsx --save-dev
npm install @prisma/client dotenv
```
</TabItem>
</TabbedContent>

:::info

If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).

:::

Once installed, initialize Prisma in your project:

Expand Down Expand Up @@ -287,32 +283,9 @@ mkdir -p lib && touch lib/prisma.ts

Now, add the following code to your `lib/prisma.ts` file:

<TabbedContent code>
<TabItem value="Prisma Postgres (recommended)">
```typescript file=lib/prisma.ts showLineNumbers
//add-start
import { PrismaClient } from '../app/generated/prisma'
import { withAccelerate } from '@prisma/extension-accelerate'

const globalForPrisma = global as unknown as {
prisma: PrismaClient
}

const prisma = globalForPrisma.prisma || new PrismaClient({
accelerateUrl: process.env.DATABASE_URL,
}).$extends(withAccelerate())

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma

export default prisma
//add-end
```
</TabItem>

<TabItem value="Other databases">
```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 {
Expand All @@ -332,8 +305,6 @@ if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
export default prisma
//add-end
```
</TabItem>
</TabbedContent>

This file creates a Prisma Client and attaches it to the global object so that only one instance of the client is created in your application. This helps resolve issues with hot reloading that can occur when using Prisma ORM with Next.js in development mode.

Expand Down Expand Up @@ -707,9 +678,10 @@ Before you deploy, you also need to tell Vercel to make sure that the Prisma Cli
"seed": "tsx prisma/seed.ts"
},
"dependencies": {
"@prisma/adapter-pg": "^6.2.1",
"@prisma/client": "^6.2.1",
"@prisma/extension-accelerate": "^1.2.1",
"next": "15.1.4",
"pg": "^8.13.1",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
Expand Down
10 changes: 8 additions & 2 deletions content/800-guides/130-docker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ This will generate a `package.json` file:
Next, install the Prisma CLI as a development dependency and Express.js for the server:

```terminal
npm install prisma --save-dev && npm install @prisma/client
npm install express
npm install prisma @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg pg dotenv express
```

:::info

If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).

:::

### 1.3. Set up Prisma ORM

Now, initialize Prisma to generate the necessary files:
Expand Down
37 changes: 13 additions & 24 deletions content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,13 @@ pnpm install
Then, add additional dependencies:

```terminal
pnpm add typescript tsx @types/node -D
```

Then install the Prisma Client extension required to use Prisma Postgres:

```terminal
pnpm add @prisma/extension-accelerate
pnpm add typescript tsx @types/node @types/pg -D
pnpm add @prisma/adapter-pg pg
```

:::info

This guide uses [Prisma Postgres](/postgres/getting-started). If you plan to use a different database, you can omit the [@prisma/extension-accelerate package](https://www.npmjs.com/package/@prisma/extension-accelerate/).
If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).

:::

Expand Down Expand Up @@ -215,40 +210,34 @@ pnpm run db:migrate

When prompted by the CLI, enter a descriptive name for your migration.

Once the migration is successful, create a `client.ts` file to initialize Prisma Client with the Accelerate extension:
Once the migration is successful, create a `client.ts` file to initialize Prisma Client with a driver adapter:

```ts file=database/client.ts
// add-start
import { PrismaClient } from "./generated/client";
import { withAccelerate } from "@prisma/extension-accelerate";
import { PrismaPg } from "@prisma/adapter-pg";

// Instantiate the extended Prisma client to infer its type
const extendedPrisma = new PrismaClient({
accelerateUrl: process.env.DATABASE_URL,
}).$extends(withAccelerate());
type ExtendedPrismaClient = typeof extendedPrisma;
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL,
});

// Use globalThis for broader environment compatibility
const globalForPrisma = globalThis as typeof globalThis & {
prisma?: ExtendedPrismaClient;
prisma?: PrismaClient;
};

// Named export with global memoization
export const prisma: ExtendedPrismaClient =
globalForPrisma.prisma ?? extendedPrisma;
export const prisma: PrismaClient =
globalForPrisma.prisma ?? new PrismaClient({
adapter,
});

if (process.env.NODE_ENV !== "production") {
globalForPrisma.prisma = prisma;
}
// add-end
```

:::info

If you're not using [Prisma Postgres](/postgres/getting-started) for your database, exclude the `import { withAccelerate }` line and `.$extends(withAccelerate())` from the line following it.

:::

Then, create an `index.ts` file to re-export the instance of Prisma Client and all generated types:

```ts file=database/index.ts
Expand Down
Loading
Loading