Skip to content

Commit 2076e5a

Browse files
authored
docs: update shadow database instructions for Prisma 6 and 7 configurations (#7346)
1 parent 12b6e41 commit 2076e5a

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

content/200-orm/300-prisma-migrate/200-understanding-prisma-migrate/200-shadow-database.mdx

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,42 @@ In some cases it might make sense (e.g. when [creating and dropping databases is
8181

8282
1. Create a dedicated database that should be used as the shadow database
8383
2. Add the connection string of that database your environment variable `SHADOW_DATABASE_URL` (or `.env` file)
84-
3. Add the [`shadowDatabaseUrl`](/orm/reference/prisma-schema-reference#datasource) field reading this environment variable:
84+
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.
85+
86+
<TabbedContent code>
87+
<TabItem value="Prisma 7 (prisma.config.ts)">
88+
89+
```ts
90+
import "dotenv/config";
91+
import { defineConfig, env } from "prisma/config";
92+
93+
export default defineConfig({
94+
schema: "prisma/schema.prisma",
95+
migrations: {
96+
path: "prisma/migrations",
97+
},
98+
datasource: {
99+
url: env("DATABASE_URL"),
100+
//highlight-next-line
101+
shadowDatabaseUrl: env("SHADOW_DATABASE_URL"),
102+
},
103+
});
104+
```
105+
106+
</TabItem>
107+
<TabItem value="Prisma 6 and below (schema.prisma)">
85108

86-
```prisma highlight=4;normal
109+
```prisma
87110
datasource db {
88111
provider = "postgresql"
89112
//highlight-next-line
90113
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
91114
}
92115
```
93116

117+
</TabItem>
118+
</TabbedContent>
119+
94120
> **Important**: Do not use the exact same values for `url` and `shadowDatabaseUrl` as that might delete all the data in your database.
95121
96122
## Cloud-hosted shadow databases must be created manually
@@ -99,16 +125,42 @@ Some cloud providers do not allow you to drop and create databases with SQL. Som
99125

100126
1. Create a dedicated cloud-hosted shadow database
101127
2. Add the URL to your environment variable `SHADOW_DATABASE_URL`
102-
3. Add the [`shadowDatabaseUrl`](/orm/reference/prisma-schema-reference#datasource) field reading this environment variable:
128+
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.
129+
130+
<TabbedContent code>
131+
<TabItem value="Prisma 7 (prisma.config.ts)">
132+
133+
```ts
134+
import "dotenv/config";
135+
import { defineConfig, env } from "prisma/config";
136+
137+
export default defineConfig({
138+
schema: "prisma/schema.prisma",
139+
migrations: {
140+
path: "prisma/migrations",
141+
},
142+
datasource: {
143+
url: env("DATABASE_URL"),
144+
//highlight-next-line
145+
shadowDatabaseUrl: env("SHADOW_DATABASE_URL"),
146+
},
147+
});
148+
```
149+
150+
</TabItem>
151+
<TabItem value="Prisma 6 and below (schema.prisma)">
103152

104-
```prisma highlight=4;normal
153+
```prisma
105154
datasource db {
106155
provider = "postgresql"
107156
//highlight-next-line
108157
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
109158
}
110159
```
111160

161+
</TabItem>
162+
</TabbedContent>
163+
112164
> **Important**: Do not use the same values for `url` and `shadowDatabaseUrl`.
113165
114166
## Shadow database user permissions

0 commit comments

Comments
 (0)