Conversation
…ortações de Decimal A atualização garante compatibilidade com o Prisma 7, melhorando a estabilidade e compatibilidade do projeto, além de corrigir importações de Decimal para o pacote runtime do Prisma, evitando problemas de compatibilidade.
📝 WalkthroughWalkthroughThis PR upgrades Prisma from v6.12.0 to v7.4.2, introducing PrismaPg adapter support, a new Prisma configuration file, and migration of import paths from runtime/library to runtime/client. Views lose primary key annotations, PrismaService is refactored with proxy-based transaction retry logic, and a postinstall patch script ensures runtime compatibility. Changes
Sequence DiagramsequenceDiagram
participant App as Application
participant Proxy as PrismaService<br/>(Proxy)
participant Adapter as PrismaPg<br/>Adapter
participant DB as Database
App->>Proxy: onModuleInit()
Proxy->>Adapter: $connect()
Adapter->>DB: Establish connection
DB-->>Adapter: Connected
Adapter-->>Proxy: Ready
App->>Proxy: $transaction(fn or array)
Proxy->>Proxy: Intercept via Proxy trap
alt Array-based transaction
Proxy->>Adapter: Execute batch with RetryPromise
else Function-based transaction
Proxy->>Adapter: Execute with timeout (60s default)<br/>and RetryPromise retries
end
Adapter->>DB: Execute queries
DB-->>Adapter: Results
Adapter-->>Proxy: Transaction complete
Proxy-->>App: Results with retry logic applied
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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. Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
backend/src/reports/relatorios/helpers/reports.params-processado.ts (1)
1-1: UsePrisma.InputJsonValuefrom@prisma/clientinstead of runtime internals.Line 1 should avoid
@prisma/client/runtime/clientfor type imports; this path is not a stable public API.♻️ Proposed fix
-import { InputJsonValue } from '@prisma/client/runtime/client'; +import { FonteRelatorio, ParlamentarCargo, Prisma, TipoRelatorio } from '@prisma/client'; ... -import { FonteRelatorio, ParlamentarCargo, TipoRelatorio } from '@prisma/client'; ... -): Promise<InputJsonValue | undefined> => { +): Promise<Prisma.InputJsonValue | undefined> => { ... - return report.parametros_processados.valueOf() as InputJsonValue; + return report.parametros_processados.valueOf() as Prisma.InputJsonValue;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/src/reports/relatorios/helpers/reports.params-processado.ts` at line 1, Replace the runtime-internal import of InputJsonValue with the public Prisma type: remove the import from '@prisma/client/runtime/client' and instead import Prisma (or directly Prisma.InputJsonValue) from '@prisma/client', then update any usages to reference Prisma.InputJsonValue (or the imported alias) so the code uses the stable public API rather than runtime internals (update the import statement that currently brings in InputJsonValue).backend/src/orcamento-planejado/entities/orcamento-planejado.entity.ts (1)
1-8: Use public Prisma API (Prisma.Decimal) instead of internal runtime import.The import from
@prisma/client/runtime/clientis an internal implementation detail that is not covered by Prisma's semantic versioning and can change between versions. TheDecimaltype is available through the publicPrismanamespace.♻️ Proposed fix
-import { Decimal } from '@prisma/client/runtime/client'; +import { Prisma } from '@prisma/client'; ... - valor_planejado: number | Decimal; + valor_planejado: number | Prisma.Decimal;This pattern is already used elsewhere in the codebase (e.g.,
variavel.service.ts).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/src/orcamento-planejado/entities/orcamento-planejado.entity.ts` around lines 1 - 8, Replace the internal runtime Decimal import with the public Prisma API: remove the import of Decimal from '@prisma/client/runtime/client' and instead reference Prisma.Decimal from the public '@prisma/client' package; update the OrcamentoPlanejado type for the valor_planejado property to use number | Prisma.Decimal and ensure the module imports Prisma (import { Prisma } from '@prisma/client') so the OrcamentoPlanejado class and its valor_planejado field compile against the supported public Prisma type.backend/src/casa-civil/dash/transferencia.service.ts (1)
26-26: Use publicPrisma.Decimalinstead of internal runtime import for upgrade safety.Line 26 imports
Decimalfrom@prisma/client/runtime/client, which is Prisma's internal/private API and unsupported across upgrades. Prisma explicitly recommends usingPrisma.Decimalfrom@prisma/clientinstead. Update the import and adjust usages fromDecimal(0)tonew Prisma.Decimal(0).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/src/casa-civil/dash/transferencia.service.ts` at line 26, The current import pulls Decimal from Prisma's internal runtime; replace that with the public API by importing Prisma from '@prisma/client' (remove the import from '@prisma/client/runtime/client') and update any constructions like Decimal(0) to use new Prisma.Decimal(0) (or Prisma.Decimal as appropriate) in transferencia.service.ts so the code uses the supported public Prisma.Decimal type instead of the internal runtime symbol.
🤖 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`:
- Around line 33-34: PrismaService is passing an undefined DATABASE_URL into new
PrismaPg which delays failure; update the PrismaService
initialization/constructor to validate process.env.DATABASE_URL immediately
(similar to the SESSION_JWT_SECRET check in jwt.strategy.ts) and throw a clear
error if missing, then construct new PrismaPg({ connectionString: databaseUrl })
using the validated value (reference symbols: PrismaService, PrismaPg,
process.env.DATABASE_URL).
---
Nitpick comments:
In `@backend/src/casa-civil/dash/transferencia.service.ts`:
- Line 26: The current import pulls Decimal from Prisma's internal runtime;
replace that with the public API by importing Prisma from '@prisma/client'
(remove the import from '@prisma/client/runtime/client') and update any
constructions like Decimal(0) to use new Prisma.Decimal(0) (or Prisma.Decimal as
appropriate) in transferencia.service.ts so the code uses the supported public
Prisma.Decimal type instead of the internal runtime symbol.
In `@backend/src/orcamento-planejado/entities/orcamento-planejado.entity.ts`:
- Around line 1-8: Replace the internal runtime Decimal import with the public
Prisma API: remove the import of Decimal from '@prisma/client/runtime/client'
and instead reference Prisma.Decimal from the public '@prisma/client' package;
update the OrcamentoPlanejado type for the valor_planejado property to use
number | Prisma.Decimal and ensure the module imports Prisma (import { Prisma }
from '@prisma/client') so the OrcamentoPlanejado class and its valor_planejado
field compile against the supported public Prisma type.
In `@backend/src/reports/relatorios/helpers/reports.params-processado.ts`:
- Line 1: Replace the runtime-internal import of InputJsonValue with the public
Prisma type: remove the import from '@prisma/client/runtime/client' and instead
import Prisma (or directly Prisma.InputJsonValue) from '@prisma/client', then
update any usages to reference Prisma.InputJsonValue (or the imported alias) so
the code uses the stable public API rather than runtime internals (update the
import statement that currently brings in InputJsonValue).
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
backend/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (26)
backend/Dockerfilebackend/package.jsonbackend/prisma.config.tsbackend/prisma/schema.prismabackend/scripts/patch-prisma-exports.jsbackend/src/api-logs/backup-scheduler.service.tsbackend/src/casa-civil/dash/transferencia.service.tsbackend/src/casa-civil/distribuicao-recurso/entities/distribuicao-recurso.entity.tsbackend/src/casa-civil/transferencia/entities/transferencia.dto.tsbackend/src/casa-civil/vinculo/entities/vinculo.entity.tsbackend/src/indicador/entities/indicador.entity.tsbackend/src/orcamento-planejado/entities/orcamento-planejado.entity.tsbackend/src/orcamento-planejado/orcamento-planejado.service.tsbackend/src/orcamento-realizado/orcamento-realizado.service.tsbackend/src/painel/dto/detalhe-painel.dto.tsbackend/src/painel/painel.service.tsbackend/src/pp/contrato-aditivo/entities/contrato-aditivo.entity.tsbackend/src/pp/contrato/contrato.service.tsbackend/src/pp/contrato/entities/contrato.entity.tsbackend/src/pp/orcamento-planejado/orcamento-planejado.service.tsbackend/src/pp/orcamento-realizado/orcamento-realizado.service.tsbackend/src/prisma/prisma.service.tsbackend/src/reports/relatorios/helpers/reports.params-processado.tsbackend/src/variavel/dto/list-variavel.dto.tsbackend/src/variavel/entities/variavel.entity.tsbackend/vendor/prisma-field-encryption.tgz
| const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }); | ||
| super({ adapter, log: logConfig }); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's examine the prisma service file
head -50 backend/src/prisma/prisma.service.tsRepository: AppCivico/smae
Length of output: 1856
🏁 Script executed:
# Check if PATTERNS.md exists and review it for environment validation guidance
cat backend/PATTERNS.md 2>/dev/null || echo "File not found, checking for similar pattern docs"Repository: AppCivico/smae
Length of output: 22118
🏁 Script executed:
# Search for DATABASE_URL references throughout the codebase to understand how it's typically handled
rg "DATABASE_URL" --type ts --type tsx -B 2 -A 2Repository: AppCivico/smae
Length of output: 85
🏁 Script executed:
# Check if there's any environment validation at app startup/module level
rg "validate.*env|process.env\." backend --type ts --type tsx | head -20Repository: AppCivico/smae
Length of output: 85
🏁 Script executed:
# Look for main.ts and app bootstrap
fd -e ts -e tsx "main\.|app\.module" backend/src --type fRepository: AppCivico/smae
Length of output: 480
🏁 Script executed:
# Check for environment validation patterns in the codebase
rg "process\.env\." backend/src --type ts -B 1 -A 1 | head -40Repository: AppCivico/smae
Length of output: 2781
🏁 Script executed:
# Look specifically for error handling or validation related to DATABASE_URL
rg "DATABASE_URL|connectionString" backend --type ts -B 2 -A 2Repository: AppCivico/smae
Length of output: 1487
🏁 Script executed:
# Check if there's an environment validation module or config
fd -e ts -e tsx "env|config" backend/src --type f | grep -E "(env|config)" | head -20Repository: AppCivico/smae
Length of output: 1392
🏁 Script executed:
# Check main.ts for bootstrap/validation
cat -n backend/src/main.tsRepository: AppCivico/smae
Length of output: 3705
🏁 Script executed:
# Check prisma.config.ts to see how env() function works
cat -n backend/prisma.config.tsRepository: AppCivico/smae
Length of output: 406
🏁 Script executed:
# Search for env validation utility
rg "function env|const env|export.*env" backend --type ts -B 1 -A 3 | head -50Repository: AppCivico/smae
Length of output: 1932
🏁 Script executed:
# Check how DATABASE_URL is used in other parts - specifically in bin/pgsql-migrate.ts
sed -n '1,30p' backend/bin/pgsql-migrate.tsRepository: AppCivico/smae
Length of output: 926
🏁 Script executed:
# Look for any environment validation or checks that happen before PrismaService is instantiated
rg "DATABASE_URL" backend/prisma --type ts -B 3 -A 3Repository: AppCivico/smae
Length of output: 40
🏁 Script executed:
# Check if there are any error patterns when DATABASE_URL is missing in the prisma logs or tests
fd -e ts -e tsx "test|spec" backend/src --type f | xargs grep -l "DATABASE_URL" 2>/dev/null | head -5Repository: AppCivico/smae
Length of output: 40
🏁 Script executed:
# Look at how the PrismaService is used - when is it first instantiated?
rg "PrismaService" backend/src/app.module.ts -B 2 -A 5Repository: AppCivico/smae
Length of output: 40
🏁 Script executed:
# Look at app.module.ts to understand when PrismaService is instantiated
head -100 backend/src/app.module.tsRepository: AppCivico/smae
Length of output: 3966
🏁 Script executed:
# Check the PrismaModule to see how it provides PrismaService
fd -e ts "prisma.module" backend/src --type fRepository: AppCivico/smae
Length of output: 93
🏁 Script executed:
# Search for any error handling or documentation about DATABASE_URL requirement
rg "DATABASE_URL" backend --type ts --type md -B 5 -A 2 | head -60Repository: AppCivico/smae
Length of output: 2395
🏁 Script executed:
# Check the prisma.module.ts file
cat -n backend/src/prisma/prisma.module.tsRepository: AppCivico/smae
Length of output: 309
🏁 Script executed:
# Check if there's any .env file documentation or requirements
fd -e md "README|SETUP|ENV|.env" backend --type f | head -10Repository: AppCivico/smae
Length of output: 157
🏁 Script executed:
# Look for any CI/CD configuration that might validate DATABASE_URL before startup
fd -e yml -e yaml ".github|docker" backend --type f | head -10Repository: AppCivico/smae
Length of output: 40
🏁 Script executed:
# Check the backend README for setup/environment documentation
head -150 backend/README.mdRepository: AppCivico/smae
Length of output: 3851
🏁 Script executed:
# Search for any .env.example or similar files
fd -e example -e sample "env" backend --type fRepository: AppCivico/smae
Length of output: 78
🏁 Script executed:
# Look at the full PrismaService to understand the complete picture
cat -n backend/src/prisma/prisma.service.tsRepository: AppCivico/smae
Length of output: 3362
🏁 Script executed:
# Check the .env.example to see if DATABASE_URL is documented
cat backend/.env.example | head -50Repository: AppCivico/smae
Length of output: 1813
🏁 Script executed:
# Search for how other critical environment variables are handled
rg "SESSION_JWT_SECRET|CLOAK_KEY" backend/src --type ts -B 2 -A 2Repository: AppCivico/smae
Length of output: 10456
Validate DATABASE_URL at service initialization for fail-fast error reporting.
The service currently passes an undefined connection string to PrismaPg, which defers the error until connection attempt and produces opaque failures. This mirrors the validation pattern already used in jwt.strategy.ts for SESSION_JWT_SECRET, ensuring critical infrastructure setup errors are caught immediately at bootstrap time.
Proposed fix
constructor() {
- const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
+ const connectionString = process.env.DATABASE_URL;
+ if (!connectionString) {
+ throw new Error('DATABASE_URL must be defined');
+ }
+ const adapter = new PrismaPg({ connectionString });
super({ adapter, log: logConfig });📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }); | |
| super({ adapter, log: logConfig }); | |
| constructor() { | |
| const connectionString = process.env.DATABASE_URL; | |
| if (!connectionString) { | |
| throw new Error('DATABASE_URL must be defined'); | |
| } | |
| const adapter = new PrismaPg({ connectionString }); | |
| super({ adapter, log: logConfig }); | |
| } |
🤖 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 33 - 34, PrismaService is
passing an undefined DATABASE_URL into new PrismaPg which delays failure; update
the PrismaService initialization/constructor to validate
process.env.DATABASE_URL immediately (similar to the SESSION_JWT_SECRET check in
jwt.strategy.ts) and throw a clear error if missing, then construct new
PrismaPg({ connectionString: databaseUrl }) using the validated value (reference
symbols: PrismaService, PrismaPg, process.env.DATABASE_URL).



Summary by CodeRabbit
Release Notes