Summary
The totalQueries counter example in the "Metrics removed" section of the Upgrade to Prisma ORM v7 guide declares total with const but then attempts to reassign it, which will throw a TypeError: Assignment to constant variable at runtime (and fail to compile under TypeScript).
Location
Current (broken) code
const total = 0;
const prisma = new PrismaClient().$extends({
client: {
$log: (s: string) => console.log(s),
async $totalQueries() {
return total;
},
},
query: {
$allModels: {
async $allOperations({ query, args }) {
total += 1; // ❌ Cannot assign to `total` because it is a constant
return query(args);
},
},
},
});
Expected fix
Change const to let:
Why this matters
This is the example users are directed to when replacing the removed Metrics preview feature, so anyone copy-pasting it as a starting point will hit an immediate runtime/compile error. It also undermines confidence in the migration guide at exactly the moment users are doing a major version upgrade.
Additional notes
- The snippet also uses
$allModels, which scopes the counter to model operations only - raw queries ($queryRaw, $executeRaw) won't be counted. Worth a brief note if the intent is a true "total queries" counter.
Summary
The
totalQueriescounter example in the "Metrics removed" section of the Upgrade to Prisma ORM v7 guide declarestotalwithconstbut then attempts to reassign it, which will throw aTypeError: Assignment to constant variableat runtime (and fail to compile under TypeScript).Location
apps/docs/content/docs/guides/upgrade-prisma-orm/v7.mdxCurrent (broken) code
Expected fix
Change
consttolet:
Why this matters
This is the example users are directed to when replacing the removed Metrics preview feature, so anyone copy-pasting it as a starting point will hit an immediate runtime/compile error. It also undermines confidence in the migration guide at exactly the moment users are doing a major version upgrade.
Additional notes
$allModels, which scopes the counter to model operations only - raw queries ($queryRaw,$executeRaw) won't be counted. Worth a brief note if the intent is a true "total queries" counter.