Skip to content

docs: Update seeding example to require adapter in Prisma ORM v7#7471

Open
kageyama0 wants to merge 3 commits intoprisma:mainfrom
kageyama0:fix/seed-adapter-v7
Open

docs: Update seeding example to require adapter in Prisma ORM v7#7471
kageyama0 wants to merge 3 commits intoprisma:mainfrom
kageyama0:fix/seed-adapter-v7

Conversation

@kageyama0
Copy link

@kageyama0 kageyama0 commented Feb 6, 2026

Summary

This PR updates the seeding documentation to reflect that Prisma ORM v7 requires an adapter or accelerateUrl option when initializing PrismaClient.

Changes

  • Updated seed.ts example to include adapter initialization using @prisma/adapter-pg
  • Added info callout explaining the v7 requirement
  • Updated dependency installation command to include @prisma/adapter-pg, pg, and dotenv

Background

In Prisma ORM v7, running new PrismaClient() without options throws:

PrismaClientInitializationError: PrismaClient needs to be constructed with a non-empty, valid PrismaClientOptions

This is a breaking change from v6 that is not currently documented in the seeding guide, causing confusion for developers migrating to v7.

Related Issues

  • Related to the v7 migration guide
  • Addresses common PrismaClientInitializationError when running prisma db seed

Testing

Tested with:

  • Prisma ORM v7.3.0
  • PostgreSQL 18
  • @prisma/adapter-pg v7.3.0

Summary by CodeRabbit

  • Documentation
    • Updated seeding workflow to showcase Prisma v7 adapter-based seeding with connection pooling.
    • Added guidance for proper pool lifecycle/shutdown in both success and error paths.
    • Expanded examples for both JavaScript and TypeScript seeds and environment configuration.
    • Documented new public usage pattern and required development dependencies for adapter-enabled seeding.

- Add adapter initialization in seed.ts example
- Update dependencies to include @prisma/adapter-pg, pg, and dotenv
- Add info callout explaining v7 requirement
- Fixes PrismaClientInitializationError when running db seed in v7
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

Walkthrough

Documentation updated to demonstrate Prisma v7 adapter-based seeding: import PrismaClient from @prisma/client, create a pg Pool, wrap it with PrismaPg adapter, instantiate PrismaClient({ adapter }), add pool.end() in success/error paths, and update dev-dependencies and examples for both TS and JS seeds.

Changes

Cohort / File(s) Summary
Seeding Pattern Documentation
content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx
Swapped default PrismaClient() examples for adapter-backed usage: added imports (@prisma/client, @prisma/adapter-pg, pg, dotenv/config), created Pool and PrismaPg adapter, passed { adapter } to PrismaClient, ensured pool.end() on success/error, and expanded dev-dependency install guidance (@prisma/adapter-pg, pg, @types/pg, dotenv).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: updating seeding documentation to reflect Prisma ORM v7's adapter requirement. It's specific, clear, and directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx (2)

150-158: ⚠️ Potential issue | 🟡 Minor

The Pool connection is never closed — add pool.end() alongside prisma.$disconnect().

When using a manually-created pg.Pool, the pool holds open connections even after prisma.$disconnect(). For a seed script that should exit cleanly, the pool should also be torn down. Without this, the Node.js process may hang instead of exiting.

Proposed fix
 main()
   .then(async () => {
     await prisma.$disconnect()
+    await pool.end()
   })
   .catch(async (e) => {
     console.error(e)
     await prisma.$disconnect()
+    await pool.end()
     process.exit(1)
   })

224-278: ⚠️ Potential issue | 🟠 Major

This JavaScript example also needs the v7 adapter treatment.

As noted above, this tab still uses const prisma = new PrismaClient() on line 226 without passing an adapter. In Prisma v7, this will fail with PrismaClientInitializationError. The same adapter pattern (using require syntax) should be applied here, along with the corresponding info callout and updated npm install command (currently missing from this tab as well — line 280 onwards doesn't list the adapter packages).

🤖 Fix all issues with AI agents
In `@content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx`:
- Around line 94-98: The JavaScript example still constructs PrismaClient
without an adapter (const prisma = new PrismaClient()), so update the JS tab to
mirror the new Prisma v7 callout: show initializing PrismaClient with an adapter
(or accelerateUrl) using CommonJS require syntax and demonstrate the PostgreSQL
adapter pattern (or add a short note that the same adapter/accelerateUrl setup
applies). Ensure references to PrismaClient, adapter, and accelerateUrl are
present in the JS example so the documented breaking change and fix are
reflected for CommonJS users.
- Around line 161-163: Update the dev dependency list to include the missing
TypeScript types for pg by adding "@types/pg" to the npm install command (so the
line with "npm install -D typescript tsx `@types/node` `@prisma/adapter-pg` pg
dotenv" becomes "... pg dotenv `@types/pg`" or equivalent); this ensures
TypeScript can resolve the "pg" module when the seed script imports "Pool" from
"pg" and prevents the "Could not find a declaration file for module 'pg'" error.
🧹 Nitpick comments (1)
content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx (1)

100-108: Consider using ts as the language identifier for this TypeScript file.

Line 100 uses ```js file=seed.ts — since the file is seed.ts and the content uses TypeScript-style ESM imports, using ts as the language identifier would give readers proper syntax highlighting cues and be more consistent with the file extension.

- Add pool.end() in both success and error handlers for TypeScript and JavaScript examples
- Update JavaScript tab to use adapter pattern (PrismaPg)
- Add @types/pg to dependencies
- Add info callout to JavaScript example explaining v7 requirement
- Add dotenv import to JavaScript example

Addresses all CodeRabbit feedback
@kageyama0
Copy link
Author

Thanks for the review! I've addressed all the feedback:

  1. ✅ Added pool.end() in both success and error handlers to prevent process hanging
  2. ✅ Updated JavaScript tab to use the adapter pattern (matching TypeScript example)
  3. ✅ Added @types/pg to the dependencies

All examples now follow the same pattern:

  • Import adapter and pg pool
  • Initialize PrismaClient with adapter
  • Clean up both prisma connection and pool in finally handlers

Re: the ts vs js syntax highlighting - I kept it as js since the original docs use that for TypeScript seed examples, but happy to change if preferred.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx (2)

232-294: ⚠️ Potential issue | 🟠 Major

Missing dependency installation step in the JavaScript tab.

The TypeScript tab (line 163-165) explicitly tells users to install @prisma/adapter-pg, pg, @types/pg, and dotenv as dev dependencies. The JavaScript tab now uses the same packages (@prisma/adapter-pg, pg, dotenv) but has no corresponding installation step — it jumps straight from the seed script to configuring prisma.config.ts.

A JS user following this guide will hit Cannot find module '@prisma/adapter-pg' on their first prisma db seed run.

Proposed fix — add a dependency step between the seed.js code block and the prisma.config.ts step

Add a new step 3 (and renumber the subsequent steps) after line 294:

    ```

+3. Add `@prisma/adapter-pg`, `pg`, and `dotenv` as development dependencies:
+   ```
+   npm install -D `@prisma/adapter-pg` pg dotenv
+   ```
+
-3. Add the `seed` field to your `prisma.config.ts` file:
+4. Add the `seed` field to your `prisma.config.ts` file:

345-356: ⚠️ Potential issue | 🟡 Minor

Raw SQL chaining example drops pool.end() from the lifecycle handlers.

This snippet is presented as a replacement for the chain at the end of the seed file. If a user adopts it verbatim after setting up the adapter pattern from the earlier section, they'll lose the pool.end() calls, leaving the connection pool open.

Since this section is meant to build on the seed.js example above, it should include pool.end() for consistency:

Proposed fix
 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)
   })
🧹 Nitpick comments (1)
content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx (1)

408-441: User-defined arguments example lacks adapter initialization — could confuse v7 users.

This standalone snippet uses prisma.$disconnect() but never shows how prisma is constructed. After the earlier sections go to great lengths to explain that v7 requires an adapter, a user landing on this section might be confused about whether the adapter pattern applies here too.

Consider adding a brief note (even a one-liner comment like // Initialize PrismaClient with adapter as shown above) or a reference back to the adapter setup section, so readers understand the same initialization requirement applies.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 6, 2026
- Split dependencies into common (typescript, tsx, @types/node, dotenv)
  and database-specific (@prisma/adapter-pg, pg, @types/pg for PostgreSQL)
- Apply to both TypeScript and JavaScript tabs
- Makes it clearer which packages are needed for each database
- Users can easily swap PostgreSQL packages for their database of choice
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx (2)

363-374: ⚠️ Potential issue | 🟡 Minor

Downstream promise-chain examples are now inconsistent — missing pool.end().

Now that the primary seed examples establish the adapter + pool pattern, users who follow the "raw SQL" section will replace their promise chain with this one — which drops pool.end(). The same issue applies to the "user-defined arguments" example at lines 450–458. Both will cause the process to hang after seeding.

Since these sections instruct users to modify the end of the seed file, they should reflect the current cleanup pattern.

Proposed fix for the raw SQL chain (lines 363–374)
 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)
   })
Proposed fix for user-defined arguments (lines 450–458)
 main()
   .then(async () => {
     await prisma.$disconnect()
+    await pool.end()
   })
   .catch(async (e) => {
     console.error(e)
     await prisma.$disconnect()
+    await pool.end()
     process.exit(1)
   })

177-194: ⚠️ Potential issue | 🟡 Minor

Duplicate step number: two "step 5"s in the TypeScript tab.

Lines 177 and 194 are both numbered as step 5. The second one ("To seed the database…") should be step 6.

Proposed fix
-5. To seed the database, run the `db seed` CLI command:
+6. To seed the database, run the `db seed` CLI command:
🧹 Nitpick comments (1)
content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx (1)

106-106: Consider using the template literal pattern for the connection string for docs consistency.

Other Prisma database adapter documentation examples use a const connectionString = \${process.env.DATABASE_URL}`` pattern before passing it to the Pool constructor. This same convention appears at line 247 in the JS tab as well. It's a small consistency nit, but keeping patterns uniform across the docs helps users recognize the same approach everywhere.

Proposed fix (TS example, line 106)
+   const connectionString = `${process.env.DATABASE_URL}`
-   const pool = new Pool({ connectionString: process.env.DATABASE_URL })
+   const pool = new Pool({ connectionString })
Proposed fix (JS example, line 247)
+   const connectionString = `${process.env.DATABASE_URL}`
-   const pool = new Pool({ connectionString: process.env.DATABASE_URL })
+   const pool = new Pool({ connectionString })

Based on learnings: "In Prisma docs, when showing examples of instantiating driver adapters with connection strings from environment variables, use the template literal pattern const connectionString = \${process.env.DATABASE_URL}`` for consistency across all database adapter examples."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant