diff --git a/apps/docs/content/docs/orm/prisma-migrate/workflows/seeding.mdx b/apps/docs/content/docs/orm/prisma-migrate/workflows/seeding.mdx index 9365b5b436..d95b2bfa4f 100644 --- a/apps/docs/content/docs/orm/prisma-migrate/workflows/seeding.mdx +++ b/apps/docs/content/docs/orm/prisma-migrate/workflows/seeding.mdx @@ -68,9 +68,20 @@ model Post { Create some new users and posts in your `prisma/seed.ts` file: +:::info[Prisma ORM v7 requirement] +In Prisma ORM v7, `PrismaClient` must be initialized with a driver adapter. The example below uses `@prisma/adapter-pg` with a PostgreSQL connection pool. +::: + ```js title="seed.ts" +import "dotenv/config"; +import { Pool } from "pg"; +import { PrismaPg } from "@prisma/adapter-pg"; import { PrismaClient } from "../prisma/generated/client"; -const prisma = new PrismaClient(); + +const connectionString = `${process.env.DATABASE_URL}`; +const pool = new Pool({ connectionString }); +const adapter = new PrismaPg(pool); +const prisma = new PrismaClient({ adapter }); async function main() { const alice = await prisma.user.upsert({ where: { email: "alice@prisma.io" }, @@ -114,18 +125,20 @@ async function main() { main() .then(async () => { await prisma.$disconnect(); + await pool.end(); }) .catch(async (e) => { console.error(e); await prisma.$disconnect(); + await pool.end(); process.exit(1); }); ``` -- Add `typescript`, `tsx` and `@types/node` development dependencies: +- Add `typescript`, `tsx`, `@types/node`, `@prisma/adapter-pg`, `pg`, `@types/pg` and `dotenv` development dependencies: ```npm -npm install -D typescript tsx @types/node +npm install -D typescript tsx @types/node @prisma/adapter-pg pg @types/pg dotenv ``` - Add the `seed` field to your `prisma.config.ts` file: @@ -176,10 +189,12 @@ main() .then(rawSql) .then(async () => { await prisma.$disconnect(); + await pool.end(); }) .catch(async (e) => { console.error(e); await prisma.$disconnect(); + await pool.end(); process.exit(1); }); ```