You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/200-orm/300-prisma-migrate/200-understanding-prisma-migrate/200-shadow-database.mdx
+56-4Lines changed: 56 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,16 +81,42 @@ In some cases it might make sense (e.g. when [creating and dropping databases is
81
81
82
82
1. Create a dedicated database that should be used as the shadow database
83
83
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
+
<TabbedContentcode>
87
+
<TabItemvalue="Prisma 7 (prisma.config.ts)">
88
+
89
+
```ts
90
+
import"dotenv/config";
91
+
import { defineConfig, env } from"prisma/config";
92
+
93
+
exportdefaultdefineConfig({
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
+
<TabItemvalue="Prisma 6 and below (schema.prisma)">
85
108
86
-
```prisma highlight=4;normal
109
+
```prisma
87
110
datasource db {
88
111
provider = "postgresql"
89
112
//highlight-next-line
90
113
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
91
114
}
92
115
```
93
116
117
+
</TabItem>
118
+
</TabbedContent>
119
+
94
120
> **Important**: Do not use the exact same values for `url` and `shadowDatabaseUrl` as that might delete all the data in your database.
95
121
96
122
## 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
99
125
100
126
1. Create a dedicated cloud-hosted shadow database
101
127
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
+
<TabbedContentcode>
131
+
<TabItemvalue="Prisma 7 (prisma.config.ts)">
132
+
133
+
```ts
134
+
import"dotenv/config";
135
+
import { defineConfig, env } from"prisma/config";
136
+
137
+
exportdefaultdefineConfig({
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
+
<TabItemvalue="Prisma 6 and below (schema.prisma)">
103
152
104
-
```prisma highlight=4;normal
153
+
```prisma
105
154
datasource db {
106
155
provider = "postgresql"
107
156
//highlight-next-line
108
157
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
109
158
}
110
159
```
111
160
161
+
</TabItem>
162
+
</TabbedContent>
163
+
112
164
> **Important**: Do not use the same values for `url` and `shadowDatabaseUrl`.
0 commit comments