diff --git a/content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx b/content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx
index 0b186e2444..6206bfe158 100644
--- a/content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx
+++ b/content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx
@@ -16,46 +16,29 @@ This guide describes how to seed your database using Prisma Client and Prisma OR
## How to seed your database in Prisma ORM
-Prisma ORM's integrated seeding functionality expects a command in the `"seed"` key in the `"prisma"` key of your `package.json` file. This can be any command, `prisma db seed` will just execute it. In this guide and as a default, we recommend writing a seed script inside your project's `prisma/` folder and starting it with the command.
-
-
-
-```json
-"prisma": {
- "seed": "ts-node prisma/seed.ts"
-},
+Prisma ORM's integrated seeding functionality expects a command in the `"seed"` key in the `migrations` object of your `prisma.config.ts`. This can be any command, `prisma db seed` will just execute it. In this guide and as a default, we recommend writing a seed script inside your project's `prisma/` folder and starting it with the command.
+
+```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"),
+ },
+});
```
-
-
-:::info
-
-With TypeScript,`ts-node` does transpiling and typechecking by default; typechecking can be disabled with the following flag `--transpile-only`.
-
-Example:
-`"seed": "ts-node --transpile-only prisma/seed.ts"`
-
-This can be useful to reduce memory usage (RAM) and increase execution speed of the seed script.
-
-:::
-
-
-
-
-```json
-"prisma": {
- "seed": "node prisma/seed.js"
-},
-```
-
-
-
## Integrated seeding with Prisma Migrate
-Database seeding happens in two ways with Prisma ORM: manually with `prisma db seed` and automatically in `prisma migrate reset` and (in some scenarios) `prisma migrate dev`.
+Database seeding happens when you run `prisma db seed`. With `prisma db seed`, _you_ decide when to invoke the seed command. It can be useful for a test setup or to prepare a new development environment, for example.
-With `prisma db seed`, _you_ decide when to invoke the seed command. It can be useful for a test setup or to prepare a new development environment, for example.
+### Prisma 6 Only
Prisma Migrate also integrates seamlessly with your seeds, assuming you follow the steps in the section below. Seeding is triggered automatically when Prisma Migrate resets the development database.
Prisma Migrate resets the database and triggers seeding in the following scenarios:
@@ -153,37 +136,28 @@ Here we suggest some specific seed scripts for different situations. You are fre
})
```
-3. Add `typescript`, `ts-node` and `@types/node` development dependencies:
+3. Add `typescript`, `tsx` and `@types/node` development dependencies:
```
- npm install -D typescript ts-node @types/node
+ npm install -D typescript tsx @types/node
```
-
-
-4. Add the `prisma.seed` field to your `package.json` file:
- ```json file=package.json highlight=5;normal
- {
- "name": "my-project",
- "version": "1.0.0",
- "prisma": {
- "seed": "ts-node prisma/seed.ts"
- },
- "devDependencies": {
- "@types/node": "^14.14.21",
- "ts-node": "^9.1.1",
- "typescript": "^4.1.3"
- }
- }
+4. Add the `seed` field to your `prisma.config.ts` file:
+ ```ts file=prisma.config.ts
+ import 'dotenv/config'
+ import { defineConfig, env } from "prisma/config";
+ export default defineConfig({
+ schema: "prisma/schema.prisma",
+ migrations: {
+ path: "prisma/migrations",
+ // add-start
+ seed: "tsx prisma/seed.ts"
+ // add-end
+ },
+ datasource: {
+ url: env("DATABASE_URL"),
+ },
+ });
```
-
- Some projects may require you to add compile options. When using Next.js for example, you would setup your seed script like so:
-
- ```json file=package.json
- "prisma": {
- "seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
- },
- ```
-
5. To seed the database, run the `db seed` CLI command:
```
npx prisma db seed
@@ -281,15 +255,22 @@ Here we suggest some specific seed scripts for different situations. You are fre
})
```
-3. Add the `prisma.seed` to your `package.json` file:
- ```json file=package.json highlight=5;normal
- {
- "name": "my-project",
- "version": "1.0.0",
- "prisma": {
- "seed": "node prisma/seed.js"
- }
- }
+3. Add the `seed` field to your `prisma.config.ts` file:
+ ```ts file=prisma.config.ts
+ import 'dotenv/config'
+ import { defineConfig, env } from "prisma/config";
+ export default defineConfig({
+ schema: "prisma/schema.prisma",
+ migrations: {
+ path: "prisma/migrations",
+ // add-start
+ seed: "node prisma/seed.js"
+ // add-end
+ },
+ datasource: {
+ url: env("DATABASE_URL"),
+ },
+ });
```
4. To seed the database, run the `db seed` CLI command:
diff --git a/content/200-orm/500-reference/380-connection-urls.mdx b/content/200-orm/500-reference/380-connection-urls.mdx
index d68457494b..0bb23ddd7b 100644
--- a/content/200-orm/500-reference/380-connection-urls.mdx
+++ b/content/200-orm/500-reference/380-connection-urls.mdx
@@ -7,7 +7,7 @@ tocDepth: 3
Prisma ORM needs a connection URL to be able to connect to your database, e.g. when sending queries with [Prisma Client](/orm/prisma-client) or when changing the database schema with [Prisma Migrate](/orm/prisma-migrate).
-The connection URL is provided via the `url` field of a `datasource` block in your Prisma schema. It usually consists of the following components (except for SQLite and [Prisma Postgres](/postgres)):
+The connection URL is provided via the `url` field of a `datasource` block in your Prisma config (or Prisma schema if on version 6). It usually consists of the following components (except for SQLite and [Prisma Postgres](/postgres)):
- **User**: The name of your database user
- **Password**: The password for your database user
@@ -66,82 +66,203 @@ DATABASE_URL="postgres://2f9881cc7eef46f094ac913df34c1fb441502fe66cbe28cc48998d4
When connecting via Prisma Accelerate, the connection string doesn't require a user/password like a conventional connection string does. Instead, authentication works via an API key:
+
+
+```ts file=prisma.config.ts
+export default defineConfig({
+ datasource: {
+ url: "prisma+postgres://accelerate.prisma-data.net/?api_key=API_KEY"
+ },
+});
+```
+
+
```prisma file=schema.prisma
datasource db {
provider = "postgresql"
url = "prisma+postgres://accelerate.prisma-data.net/?api_key=API_KEY"
}
```
+
+
+
In this snippet, `API_KEY` is a placeholder for the API key you are receiving when setting up a new Prismas Postgres instance via the [Prisma Console](https://console.prisma.io). Here is an example for what a real connection URL to Prisma Postgres may look like:
+
+
+```ts file=prisma.config.ts
+export default defineConfig({
+ datasource: {
+ url: "prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGlfa2V5IjoiMGNkZTFlMjQtNzhiYi00NTY4LTkyM2EtNWUwOTEzZWUyNjU1IiwidGVuYW50X2lkIjoiNzEyZWRlZTc1Y2U2MDk2ZjI4NDg3YjE4NWMyYzA2OTNhNGMxNzJkMjhhOWFlNGUwZTYxNWE4NWIxZWY1YjBkMCIsImludGVybmFsX3NlY3JldCI6IjA4MzQ2Y2RlLWI5ZjktNDQ4Yy04NThmLTMxNjg4ODEzNmEzZCJ9.N1Za6q6NfInzHvRkud6Ojt_-RFg18a0601vdYWGKOrk"
+ },
+});
+```
+
+
```prisma file=schema.prisma
datasource db {
provider = "postgresql"
url = "prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGlfa2V5IjoiMGNkZTFlMjQtNzhiYi00NTY4LTkyM2EtNWUwOTEzZWUyNjU1IiwidGVuYW50X2lkIjoiNzEyZWRlZTc1Y2U2MDk2ZjI4NDg3YjE4NWMyYzA2OTNhNGMxNzJkMjhhOWFlNGUwZTYxNWE4NWIxZWY1YjBkMCIsImludGVybmFsX3NlY3JldCI6IjA4MzQ2Y2RlLWI5ZjktNDQ4Yy04NThmLTMxNjg4ODEzNmEzZCJ9.N1Za6q6NfInzHvRkud6Ojt_-RFg18a0601vdYWGKOrk"
}
```
+
+
+
#### Local Prisma Postgres
The connection string for connecting to a [local Prisma Postgres](/postgres/database/local-development) instance mirrors the structure of a remote instance via Accelerate:
+
+
+
+```ts file=prisma.config.ts
+export default defineConfig({
+ datasource: {
+ url: "prisma+postgres://accelerate.prisma-data.net/?api_key=API_KEY"
+ },
+});
+```
+
+
```prisma file=schema.prisma
datasource db {
provider = "postgresql"
url = "prisma+postgres://accelerate.prisma-data.net/?api_key=API_KEY"
}
```
+
+
+
However, in this case the `API_KEY` doesn't provide authentication details. Instead, it encodes information about the local Prisma Postgres instance. You can obtain a local connection string via the [`prisma dev`](/orm/reference/prisma-cli-reference#dev) command.
### PostgreSQL
+
+
+
+```ts file=prisma.config.ts
+export default defineConfig({
+ datasource: {
+ url: "postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample"
+ },
+});
+```
+
+
+
```prisma file=schema.prisma
datasource db {
provider = "postgresql"
url = "postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample"
}
```
+
+
+
### MySQL
+
+
+
+```ts file=prisma.config.ts
+export default defineConfig({
+ datasource: {
+ url: "mysql://janedoe:mypassword@localhost:3306/mydb"
+ },
+});
+```
+
+
```prisma file=schema.prisma
datasource db {
provider = "mysql"
url = "mysql://janedoe:mypassword@localhost:3306/mydb"
}
```
+
+
+
### Microsoft SQL Server
+
+
+
+```ts file=prisma.config.ts
+export default defineConfig({
+ datasource: {
+ url: "sqlserver://localhost:1433;initial catalog=sample;user=sa;password=mypassword;"
+ },
+});
+```
+
+
```prisma file=schema.prisma
datasource db {
provider = "sqlserver"
url = "sqlserver://localhost:1433;initial catalog=sample;user=sa;password=mypassword;"
}
```
+
+
+
### SQLite
+
+
+
+```ts file=prisma.config.ts
+export default defineConfig({
+ datasource: {
+ url: "file:./dev.db"
+ },
+});
+```
+
+
```prisma file=schema.prisma
datasource db {
provider = "sqlite"
url = "file:./dev.db"
}
```
+
+
+
### CockroachDB
+
+
+
+```ts file=prisma.config.ts
+export default defineConfig({
+ datasource: {
+ url: "postgresql://janedoe:mypassword@localhost:26257/mydb?schema=public"
+ },
+});
+```
+
+
```prisma file=schema.prisma
datasource db {
provider = "cockroachdb"
url = "postgresql://janedoe:mypassword@localhost:26257/mydb?schema=public"
}
```
+
+
+
### MongoDB
+_Support for MongoDB is limited to Prisma 6. We're working on support for MongoDB in Prisma 7_
+
```prisma file=schema.prisma
datasource db {
provider = "mongodb"
diff --git a/content/800-guides/070-cloudflare-d1.mdx b/content/800-guides/070-cloudflare-d1.mdx
index 017e638d21..18eb78b112 100644
--- a/content/800-guides/070-cloudflare-d1.mdx
+++ b/content/800-guides/070-cloudflare-d1.mdx
@@ -266,11 +266,15 @@ export default {
const users = await prisma.user.findMany();
const result = JSON.stringify(users);
+ ctx.waitUntil(prisma.$disconnect()); // or just await prisma.$disconnect()
return new Response(result);
},
};
```
+We explicitly call `prisma.$disconnect()` here to guarantee timely release of resources or else the
+worker might run out of memory.
+
## 7. Run the Worker locally
With the database query in place and Prisma Client generated, you can run the Worker locally.