Skip to content

Upgrade de versão do prisma#590

Open
lucasansei wants to merge 1 commit intohomolfrom
feat/upgrade-prisma-v6
Open

Upgrade de versão do prisma#590
lucasansei wants to merge 1 commit intohomolfrom
feat/upgrade-prisma-v6

Conversation

@lucasansei
Copy link
Member

@lucasansei lucasansei commented Feb 25, 2026

Summary by CodeRabbit

Release Notes

  • Chores

    • Updated minimum Node.js version requirement to 18.18.0 and npm to 9.0.0.
    • Upgraded Prisma database dependencies to version 6.19.2.
  • Refactor

    • Enhanced transaction handling and database connectivity management.
    • Adjusted database view schema structure for improved data consistency.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

Prisma dependencies upgraded to version 6.19.2 with Node.js engine constraints added. Prisma schema views refactored to remove primary key designations from multiple fields. PrismaService restructured to directly extend PrismaClient with Proxy-based transaction handling and field encryption extension integration.

Changes

Cohort / File(s) Summary
Dependency Updates
backend/package.json
Updated Prisma packages to ^6.19.2; added Node.js >=18.18.0 and npm >=9.0.0 engine requirements.
Schema View Refactoring
backend/prisma/schema.prisma
Removed @id primary key designations from 17 views including ViewProjetoMDO, ViewProjetoV2, view_meta_pessoa_responsavel, ViewNotas, and others; affected fields converted from primary keys to plain Int fields.
PrismaService Architecture
backend/src/prisma/prisma.service.ts
Restructured to extend PrismaClient directly with Proxy-based transaction handling; replaced fieldEncryptionMiddleware with fieldEncryptionExtension; introduced log configuration and dynamic $transaction override supporting array and function arguments with RetryPromise semantics.
Backup Scheduler Type Refinement
backend/src/api-logs/backup-scheduler.service.ts
Updated scheduleApiLogBackupTasks parameter type from Omit<PrismaService> to Prisma.TransactionClient for precise transactional context.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 Whiskers twitching with glee,
Prisma now 6.19 runs free,
Views shed their keys with a bound,
Proxy patterns abound!
TypeScript and transactions align,
This refactor is truly divine!

🚥 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 'Upgrade de versão do prisma' accurately describes the main objective of the pull request, which is to upgrade Prisma to a newer version (6.12.0 to 6.19.2).
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.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/upgrade-prisma-v6

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

@sonarqubecloud
Copy link

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: 1

🧹 Nitpick comments (1)
backend/src/prisma/prisma.service.ts (1)

37-67: Prefer NestJS factory provider pattern over constructor return.

The Proxy pattern works with NestJS lifecycle hooks (Nest calls onModuleInit() on the returned instance), but returning from a constructor is not the idiomatic NestJS approach. Use a factory provider instead for cleaner DI integration and to avoid prototype/instanceof issues:

const PRISMA_SERVICE = Symbol('PRISMA_SERVICE');

`@Module`({
  providers: [
    {
      provide: PRISMA_SERVICE,
      useFactory: () => {
        const client = new PrismaClient({ log: logConfig });
        const extended = client.$extends(fieldEncryptionExtension());
        return new Proxy(extended, { /* handler */ });
      },
    },
  ],
  exports: [PRISMA_SERVICE],
})
export class PrismaModule {}

This keeps the proxy behavior while maintaining NestJS best practices for custom providers.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/prisma/prisma.service.ts` around lines 37 - 67, Replace the
constructor-based Proxy return with a Nest factory provider: instead of
returning a Proxy from the PrismaService constructor, create a provider (e.g.
PRISMA_SERVICE) with a useFactory that instantiates PrismaClient, applies the
fieldEncryptionExtension() to produce extended, and then returns the Proxy
wrapping extended with the existing handler that implements onModuleInit and the
$transaction retry logic (using RetryPromise). Ensure the factory provider is
registered in the module's providers and exported so DI consumers receive the
proxied instance and Nest lifecycle hooks (onModuleInit) and instanceof behavior
work correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/src/prisma/prisma.service.ts`:
- Line 50: The jitter argument passed to RetryPromise in the two calls using
RetryPromise(transactionPromiseFn, 10, 10000, 2000) is too large (2000) and,
given the backoff formula, can lead to multi-hour sleeps; update both call sites
that invoke RetryPromise(transactionPromiseFn, 10, 10000, 2000) to use a much
smaller fixed jitter (e.g., 200) or compute a bounded jitter relative to the
base delay (for example cap jitter to a small percentage of the base delay),
ensuring jitter cannot grow unbounded and replacing the literal 2000 in both
occurrences.

---

Nitpick comments:
In `@backend/src/prisma/prisma.service.ts`:
- Around line 37-67: Replace the constructor-based Proxy return with a Nest
factory provider: instead of returning a Proxy from the PrismaService
constructor, create a provider (e.g. PRISMA_SERVICE) with a useFactory that
instantiates PrismaClient, applies the fieldEncryptionExtension() to produce
extended, and then returns the Proxy wrapping extended with the existing handler
that implements onModuleInit and the $transaction retry logic (using
RetryPromise). Ensure the factory provider is registered in the module's
providers and exported so DI consumers receive the proxied instance and Nest
lifecycle hooks (onModuleInit) and instanceof behavior work correctly.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 630b055 and b681a64.

⛔ Files ignored due to path filters (1)
  • backend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • backend/package.json
  • backend/prisma/schema.prisma
  • backend/src/api-logs/backup-scheduler.service.ts
  • backend/src/prisma/prisma.service.ts

const transactionPromiseFn = async () => {
return target.$transaction(arg, options);
};
return RetryPromise(transactionPromiseFn, 10, 10000, 2000);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix RetryPromise jitter argument value.

On Line 50 and Line 59, RetryPromise(transactionPromiseFn, 10, 10000, 2000) sets jitter to 2000. With your RetryPromise formula, that can produce multi-hour retry sleeps.

🐛 Proposed fix
-                            return RetryPromise(transactionPromiseFn, 10, 10000, 2000);
+                            return RetryPromise(transactionPromiseFn, 10, 10_000, 0.2);
...
-                            return RetryPromise(transactionPromiseFn, 10, 10000, 2000);
+                            return RetryPromise(transactionPromiseFn, 10, 10_000, 0.2);

Also applies to: 59-59

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/prisma/prisma.service.ts` at line 50, The jitter argument passed
to RetryPromise in the two calls using RetryPromise(transactionPromiseFn, 10,
10000, 2000) is too large (2000) and, given the backoff formula, can lead to
multi-hour sleeps; update both call sites that invoke
RetryPromise(transactionPromiseFn, 10, 10000, 2000) to use a much smaller fixed
jitter (e.g., 200) or compute a bounded jitter relative to the base delay (for
example cap jitter to a small percentage of the base delay), ensuring jitter
cannot grow unbounded and replacing the literal 2000 in both occurrences.

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