Skip to content

Conversation

@jamiter
Copy link
Contributor

@jamiter jamiter commented Nov 24, 2025

This was for us the only thing required (together with #2305) to make zenstack compatible with prisma v7.

Related: #2309

@ymc9, would you consider these changes?

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 24, 2025

📝 Walkthrough

Walkthrough

Selects Prisma runtime import subpath based on detected Prisma version, imports @prisma/client with that subpath, and restricts adding the --no-engine generation flag to Prisma versions >=5.2.0 and <7.0.0; updates enhancer import creation and generation flow accordingly.

Changes

Cohort / File(s) Summary
Version-aware Prisma runtime imports & engine flag handling
packages/schema/src/plugins/enhancer/enhance/index.ts
Determine Prisma version and set runtimeLibraryImportSubPath (/runtime/client for Prisma >=7.0.0, otherwise /runtime/library); import @prisma/client${runtimeLibraryImportSubPath} when generating for new Prisma client; apply --no-engine only when version exists and is >=5.2.0 and <7.0.0; adjust logical import creation and generation control flow to respect these rules.

Sequence Diagram(s)

sequenceDiagram
    participant Enhancer
    participant VersionChecker
    participant Generator

    Enhancer->>VersionChecker: getPrismaVersion()
    VersionChecker-->>Enhancer: version (e.g., 6.8.0 or 7.1.0)

    alt version >= 7.0.0
        note right of Enhancer `#E6F0FF`: New-client path
        Enhancer->>Enhancer: runtimeSubPath = '/runtime/client'
        Enhancer->>Generator: generateLogicalPrisma(import='@prisma/client/runtime/client', flags=[...])
    else version < 7.0.0
        note right of Enhancer `#FFF5E6`: Legacy-client path
        Enhancer->>Enhancer: runtimeSubPath = '/runtime/library'
        alt version >= 5.2.0
            Enhancer->>Generator: generateLogicalPrisma(import='@prisma/client/runtime/library', flags=['--no-engine', ...])
        else
            Enhancer->>Generator: generateLogicalPrisma(import='@prisma/client/runtime/library', flags=[...])
        end
    end

    Generator-->>Enhancer: generated artifacts
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review version comparison logic and boundary inclusivity for 5.2.0 and 7.0.0.
  • Verify the chosen runtime subpaths exist and are correct for targeted Prisma versions.
  • Inspect conditional assembly of import strings and flag application in the enhancer generation flow.

Possibly related PRs

Suggested reviewers

  • ymc9

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly matches the main objective of the changeset: making the enhance function compatible with Prisma v7 through version-aware runtime imports and conditional flag handling.
Description check ✅ Passed The description is related to the changeset, explaining that these changes were required for Prisma v7 compatibility and referencing the related GitHub issue and PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@jamiter jamiter changed the base branch from dev to main November 24, 2025 10:56
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)
packages/schema/src/plugins/enhancer/enhance/index.ts (1)

437-442: Align --no-engine condition with “version supports” comment and avoid unknown-version risk

The condition:

if (!prismaVersion || (semver.gte(prismaVersion, '5.2.0') && semver.lt(prismaVersion, '7.0.0'))) {

adds --no-engine even when prismaVersion is unknown, but the comment says “if the prisma version supports”. For an unknown or older Prisma, this can cause prisma generate to fail with an unrecognized flag, and the retry path reuses the same command.

To better match the comment and be safer for unknown versions:

-        const prismaVersion = getPrismaVersion();
-        if (!prismaVersion || (semver.gte(prismaVersion, '5.2.0') && semver.lt(prismaVersion, '7.0.0'))) {
+        const prismaVersion = getPrismaVersion();
+        if (prismaVersion && semver.gte(prismaVersion, '5.2.0') && semver.lt(prismaVersion, '7.0.0')) {
             // add --no-engine to reduce generation size if the prisma version supports
             // v7 has removed this option completely, because it no longer generates an engine
             generateCmd += ' --no-engine';
         }

That way --no-engine is only used when you positively know the version is in the supported range.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb0aa0f and 9aff192.

📒 Files selected for processing (1)
  • packages/schema/src/plugins/enhancer/enhance/index.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/schema/src/plugins/enhancer/enhance/index.ts (1)
packages/sdk/src/prisma.ts (1)
  • getPrismaVersion (60-79)

@ymc9 ymc9 changed the base branch from main to dev November 24, 2025 18:43
Copy link
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

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

Hi @jamiter , thanks for making this PR. Could you take a look at my comments?

v7 has the new /runtime/client path.
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

♻️ Duplicate comments (1)
packages/schema/src/plugins/enhancer/enhance/index.ts (1)

318-320: Critical: Guard semver.gte against undefined Prisma version

This issue was already identified in a previous review and remains unfixed. getPrismaVersion() returns string | undefined, so calling semver.gte(prismaVersion, '7.0.0') without a guard will cause type-checking failures and runtime errors when the version cannot be determined. Other semver.gte calls in this file (lines 341, 438) are properly guarded.

Apply this diff to add the guard:

 const prismaVersion = getPrismaVersion();
-const runtimeLibraryImportSubPath = semver.gte(prismaVersion, '7.0.0') ? '/runtime/client' : '/runtime/library';
+const runtimeLibraryImportSubPath = 
+    prismaVersion && semver.gte(prismaVersion, '7.0.0') ? '/runtime/client' : '/runtime/library';
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9aff192 and 0bd06ae.

📒 Files selected for processing (1)
  • packages/schema/src/plugins/enhancer/enhance/index.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/schema/src/plugins/enhancer/enhance/index.ts (1)
packages/sdk/src/prisma.ts (1)
  • getPrismaVersion (60-79)
🔇 Additional comments (1)
packages/schema/src/plugins/enhancer/enhance/index.ts (1)

437-442: Verify intended behavior for undefined Prisma version

The condition !prismaVersion || (semver.gte(prismaVersion, '5.2.0') && semver.lt(prismaVersion, '7.0.0')) applies the --no-engine flag when the version is undefined OR when it's in the range [5.2.0, 7.0.0). However, the AI-generated summary states the flag should be applied "only when Prisma version exists and is in [5.2.0, 7.0.0)", which would exclude the undefined case.

Please confirm the intended behavior:

  • Should --no-engine be applied when the version cannot be determined (current behavior)?
  • Or should it only be applied when the version is known to be in [5.2.0, 7.0.0) (as per AI summary)?

If the latter is correct, the condition should be:

-if (!prismaVersion || (semver.gte(prismaVersion, '5.2.0') && semver.lt(prismaVersion, '7.0.0'))) {
+if (prismaVersion && semver.gte(prismaVersion, '5.2.0') && semver.lt(prismaVersion, '7.0.0')) {

And implement other AI feedback about checking `prismaVersion`
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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0bd06ae and 03309b3.

📒 Files selected for processing (1)
  • packages/schema/src/plugins/enhancer/enhance/index.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/schema/src/plugins/enhancer/enhance/index.ts (1)
packages/sdk/src/prisma.ts (1)
  • getPrismaVersion (60-79)
🔇 Additional comments (1)
packages/schema/src/plugins/enhancer/enhance/index.ts (1)

317-334: Prisma v7 runtime path handling looks correct

Using runtimeLibraryImportSubPath to switch between /runtime/client for Prisma >= 7.0.0 and /runtime/library otherwise, plus the guarded getPrismaVersion()/semver.gte check, aligns with the reported v7 layout and avoids calling semver on undefined. The template literal for runtimeLibraryImport also fixes the earlier non-interpolated string issue.

No further changes needed here.

Copy link
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @jamiter ! Will merge when CI passes and include it in the upcoming release.

@ymc9 ymc9 merged commit bfa40c1 into zenstackhq:dev Nov 24, 2025
8 checks passed
@jamiter jamiter deleted the patch-1 branch November 24, 2025 20:20
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.

2 participants