Skip to content

docs(docs): fix const reassignment in v7 upgrade Metrics example#7814

Open
nielskaspers wants to merge 1 commit intoprisma:mainfrom
nielskaspers:docs/issue-7810-metrics-const-let
Open

docs(docs): fix const reassignment in v7 upgrade Metrics example#7814
nielskaspers wants to merge 1 commit intoprisma:mainfrom
nielskaspers:docs/issue-7810-metrics-const-let

Conversation

@nielskaspers
Copy link
Copy Markdown

@nielskaspers nielskaspers commented Apr 22, 2026

Summary

The `totalQueries` counter example in the "Metrics removed" section of the Upgrade to Prisma ORM v7 guide declares `total` with `const` but reassigns it inside `$allOperations`. As written, the example throws `TypeError: Assignment to constant variable` at runtime (and fails to compile under TypeScript).

Issue

Fixes #7810

Changes

  • `apps/docs/content/docs/guides/upgrade-prisma-orm/v7.mdx`: change `const total = 0;` to `let total = 0;` so the counter example actually runs.

Testing

  • Docs-only change. The surrounding snippet is unchanged; the only edit is the binding keyword.

Summary by CodeRabbit

  • Documentation
    • Fixed a code example in the Prisma ORM v7 upgrade guide to ensure proper execution.

The totalQueries counter example in the "Metrics removed" section
declared `total` with `const` but reassigned it inside `$allOperations`,
which throws `TypeError: Assignment to constant variable` at runtime.
Change `const` to `let` so the example actually runs.

Closes prisma#7810
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 22, 2026

@nielskaspers is attempting to deploy a commit to the Prisma Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

Walkthrough

Documentation code example in the Upgrade to Prisma ORM v7 guide is corrected where a variable declaration changes from const to let to permit variable reassignment within a query extension method.

Changes

Cohort / File(s) Summary
Documentation example fix
apps/docs/content/docs/guides/upgrade-prisma-orm/v7.mdx
Variable declaration in the "Metrics removed" code example corrected from const total = 0; to let total = 0; to allow the total variable to be incremented within the query extension callback.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the primary change: fixing a const-to-let reassignment in the v7 Metrics documentation example.
Linked Issues check ✅ Passed The code change directly addresses the core requirement from issue #7810 by changing const total = 0; to let total = 0; to allow reassignment in the example.
Out of Scope Changes check ✅ Passed The change is narrowly scoped to fixing the documented bug—a single variable declaration type in one code example with no unrelated modifications.
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
Copy Markdown
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.

🧹 Nitpick comments (1)
apps/docs/content/docs/guides/upgrade-prisma-orm/v7.mdx (1)

313-317: Consider adding an actual query operation to demonstrate the counter.

The example's main() function doesn't execute any database queries, so totalQueries will always return 0. Adding a query operation (e.g., await prisma.user.findMany()) before checking the total would better demonstrate the counter in action.

📚 Suggested enhancement for clarity
 async function main() {
-  prisma.$log("Hello world");
+  // Execute a sample query to demonstrate the counter
+  await prisma.user.findMany();
+  
   const totalQueries = await prisma.$totalQueries();
-  console.log(totalQueries);
+  console.log(`Total queries executed: ${totalQueries}`); // Outputs: 1
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/docs/content/docs/guides/upgrade-prisma-orm/v7.mdx` around lines 313 -
317, The example main() currently never runs a DB query so
prisma.$totalQueries() returns 0; modify main() to perform at least one query
(e.g., await prisma.user.findMany() or another model query) before calling
prisma.$totalQueries() so the counter reflects executed queries; update
references around the prisma.$log and prisma.$totalQueries() calls to place the
query (await prisma.user.findMany()) prior to reading totalQueries.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/docs/content/docs/guides/upgrade-prisma-orm/v7.mdx`:
- Around line 313-317: The example main() currently never runs a DB query so
prisma.$totalQueries() returns 0; modify main() to perform at least one query
(e.g., await prisma.user.findMany() or another model query) before calling
prisma.$totalQueries() so the counter reflects executed queries; update
references around the prisma.$log and prisma.$totalQueries() calls to place the
query (await prisma.user.findMany()) prior to reading totalQueries.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c06a1f20-c206-4681-a3d5-d4a4dccbabe0

📥 Commits

Reviewing files that changed from the base of the PR and between 894b7f9 and d3084cc.

📒 Files selected for processing (1)
  • apps/docs/content/docs/guides/upgrade-prisma-orm/v7.mdx

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.

Docs bug: const total = 0 mutated in "Metrics removed" example (Upgrade to v7)

1 participant