Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,42 @@ In some cases it might make sense (e.g. when [creating and dropping databases is

1. Create a dedicated database that should be used as the shadow database
2. Add the connection string of that database your environment variable `SHADOW_DATABASE_URL` (or `.env` file)
3. Add the [`shadowDatabaseUrl`](/orm/reference/prisma-schema-reference#datasource) field reading this environment variable:
3. In Prisma 7, configure the `shadowDatabaseUrl` field in `prisma.config.ts` under the `datasource` object. In Prisma 6 and below, add the `shadowDatabaseUrl` field to the `datasource` block in your `schema.prisma` file.

<TabbedContent code>
<TabItem value="Prisma 7 (prisma.config.ts)">

```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"),
//highlight-next-line
shadowDatabaseUrl: env("SHADOW_DATABASE_URL"),
},
});
```

</TabItem>
<TabItem value="Prisma 6 and below (schema.prisma)">

```prisma highlight=4;normal
```prisma
datasource db {
provider = "postgresql"
//highlight-next-line
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}
```

</TabItem>
</TabbedContent>

> **Important**: Do not use the exact same values for `url` and `shadowDatabaseUrl` as that might delete all the data in your database.

## Cloud-hosted shadow databases must be created manually
Expand All @@ -99,16 +125,42 @@ Some cloud providers do not allow you to drop and create databases with SQL. Som

1. Create a dedicated cloud-hosted shadow database
2. Add the URL to your environment variable `SHADOW_DATABASE_URL`
3. Add the [`shadowDatabaseUrl`](/orm/reference/prisma-schema-reference#datasource) field reading this environment variable:
3. In Prisma 7, configure the `shadowDatabaseUrl` field in `prisma.config.ts` under the `datasource` object. In Prisma 6 and below, add the `shadowDatabaseUrl` field to the `datasource` block in your `schema.prisma` file.

<TabbedContent code>
<TabItem value="Prisma 7 (prisma.config.ts)">

```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"),
//highlight-next-line
shadowDatabaseUrl: env("SHADOW_DATABASE_URL"),
},
});
```

</TabItem>
<TabItem value="Prisma 6 and below (schema.prisma)">

```prisma highlight=4;normal
```prisma
datasource db {
provider = "postgresql"
//highlight-next-line
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}
```

</TabItem>
</TabbedContent>

> **Important**: Do not use the same values for `url` and `shadowDatabaseUrl`.

## Shadow database user permissions
Expand Down
Loading