Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support for Prisma 5.16.0 #1541

Merged
merged 2 commits into from
Jun 28, 2024
Merged

fix: support for Prisma 5.16.0 #1541

merged 2 commits into from
Jun 28, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Jun 27, 2024

Fixes #1536

Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

Walkthrough

The changes primarily focus on integrating support for Prisma version 5.16.0 and dynamically handling Prisma client initialization options. This includes modifying the enhance function to conditionally include type parameters, updating dependency versions in tests and scripts, re-enabling a previously skipped test, and introducing new options for configurable Prisma client initialization in the schema.ts module.

Changes

Files Summary
packages/schema/src/plugins/enhancer/enhance/index.ts Updated enhance function to conditionally include ClientOptions based on Prisma version.
script/test-scaffold.ts, tests/integration/tests/... Updated Prisma versions from 5.15.x to 5.16.x.
tests/regression/tests/issue-925.test.ts Re-enabled a previously skipped test case related to reference with this.
packages/testtools/src/schema.ts Added prismaClientOptions to SchemaLoadOptions and updated loadSchema for dynamic options.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script[test-scaffold.ts]
    participant Enhance[enhance/index.ts]
    participant Schema[schema.ts]
    participant PrismaClient[@prisma/client]

    User->>Script: Run tests with updated Prisma versions
    Script->>PrismaClient: Install Prisma 5.16.x
    Note over Script,PrismaClient: Updated dependencies

    User->>Enhance: Call `enhance` function
    Note right of Enhance: Checks Prisma version
    Enhance-->>User: Returns enhanced object
    Note over User,Enhance: Conditional ClientOptions

    User->>Schema: Call `loadSchema` with options
    Schema->>PrismaClient: Initialize with `prismaClientOptions`
    PrismaClient->>Schema: Return Prisma Client instance
    Schema-->>User: Returns loaded schema
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

Outside diff range and nitpick comments (1)
packages/schema/src/plugins/enhancer/enhance/index.ts (1)

Line range hint 511-511: Optimization suggestion: Replace flatMap with flat.

The static analysis tool identified an unnecessary use of flatMap where flat would be sufficient. This change will simplify the code and potentially improve performance.

- .flatMap(...)
+ .flat()
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 303f103 and d0a07e8.

Files ignored due to path filters (7)
  • packages/runtime/package.json is excluded by !**/*.json
  • packages/schema/package.json is excluded by !**/*.json
  • packages/sdk/package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/*.yaml
  • tests/integration/test-run/package.json is excluded by !**/*.json
  • tests/integration/tests/frameworks/nextjs/test-project/package.json is excluded by !**/*.json
  • tests/integration/tests/frameworks/trpc/test-project/package.json is excluded by !**/*.json
Files selected for processing (4)
  • packages/schema/src/plugins/enhancer/enhance/index.ts (2 hunks)
  • script/test-scaffold.ts (1 hunks)
  • tests/integration/tests/cli/plugins.test.ts (2 hunks)
  • tests/regression/tests/issue-925.test.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • script/test-scaffold.ts
  • tests/integration/tests/cli/plugins.test.ts
Additional context used
Biome
packages/schema/src/plugins/enhancer/enhance/index.ts

[error] 511-511: Avoid unnecessary callback in flatMap call.

You can just use flat to flatten the array.
Safe fix: Replace unnecessary flatMap call to flat instead.

(lint/correctness/noFlatMapIdentity)

Additional comments not posted (2)
tests/regression/tests/issue-925.test.ts (1)

38-38: Test case re-enabled: "reference with this".

The test case has been re-enabled to verify behavior with the usage of this in model references. Ensure that this test passes with the new Prisma version and that it accurately reflects the intended behavior.

packages/schema/src/plugins/enhancer/enhance/index.ts (1)

Line range hint 162-182: Updated function signature in enhance to support Prisma 5.16.0.

The function now conditionally includes a ClientOptions type parameter based on the Prisma version. This change is crucial for supporting new features in Prisma 5.16.0. Ensure that the version check using semver.gte is robust and correctly identifies versions >= 5.16.0.

Verification successful

Updated function signature in enhance to support Prisma 5.16.0

The function now conditionally includes a ClientOptions type parameter based on the Prisma version. This change is crucial for supporting new features in Prisma 5.16.0. Ensure that the version check using semver.gte is robust and correctly identifies versions >= 5.16.0.

  • The hasClientOptions boolean is correctly implemented to check for Prisma version >= 5.16.0.
  • The function signatures correctly include or exclude the ClientOptions parameter based on this boolean.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct functioning of the `enhance` function with and without the `ClientOptions` parameter.

# Test: Check for correct conditional inclusion of `ClientOptions` in different Prisma versions.
ast-grep --lang typescript --pattern $'export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs${
$$$}>(prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs$$$>, context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs$$$>${this.generatePermissionChecker ? ' & ModelCheckers' : ''};' packages/schema/src/plugins/enhancer/enhance/index.ts

Length of output: 946



Script:

#!/bin/bash
# Description: Verify the correct functioning of the `enhance` function with and without the `ClientOptions` parameter.

# Test: Check for the function signature without `ClientOptions`.
ast-grep --lang typescript --pattern $'export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs>(
    prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs>,
    context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs>${this.generatePermissionChecker ? ' & ModelCheckers' : ''};' packages/schema/src/plugins/enhancer/enhance/index.ts

# Test: Check for the function signature with `ClientOptions`.
ast-grep --lang typescript --pattern $'export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs, ClientOptions>(
    prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs, ClientOptions>,
    context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs, ClientOptions>${this.generatePermissionChecker ? ' & ModelCheckers' : ''};' packages/schema/src/plugins/enhancer/enhance/index.ts

Length of output: 1931



Script:

#!/bin/bash
# Description: Verify the correct functioning of the `enhance` function with and without the `ClientOptions` parameter.

# Test: Check for the function signature without `ClientOptions`.
ast-grep --lang typescript --pattern $'export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs>(
    prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs>,
    context?: EnhancementContext<any>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs>;' packages/schema/src/plugins/enhancer/enhance/index.ts

# Test: Check for the function signature with `ClientOptions`.
ast-grep --lang typescript --pattern $'export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs, ClientOptions>(
    prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs, ClientOptions>,
    context?: EnhancementContext<any>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs, ClientOptions>;' packages/schema/src/plugins/enhancer/enhance/index.ts

Length of output: 928



Script:

#!/bin/bash
# Description: Output the content of the index.ts file to manually verify the function signatures.

cat packages/schema/src/plugins/enhancer/enhance/index.ts

Length of output: 25323

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

Outside diff range and nitpick comments (1)
packages/testtools/src/schema.ts (1)

Line range hint 72-74: Remove unnecessary else clause as indicated by static analysis.

The static analysis tool has flagged an unnecessary else clause. This can be simplified to enhance code readability and maintainability.

- else {
-     // code block
- }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d0a07e8 and 9ec7287.

Files selected for processing (2)
  • packages/testtools/src/schema.ts (2 hunks)
  • tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts (2 hunks)
Additional context used
Biome
packages/testtools/src/schema.ts

[error] 72-74: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

Additional comments not posted (4)
tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts (2)

58-122: Ensure global settings for omit are correctly applied and tested.

This test case is crucial as it tests the global application of the omit settings. Verify that the settings are correctly applied to the Prisma client and that the test assertions accurately reflect these settings. This includes checking that omitted fields do not appear in the results and that non-omitted fields are handled correctly.

Verification successful

Verified: Global settings for omit are correctly applied and tested.

The prismaClientOptions are correctly merged with the default options and used to instantiate the PrismaClient. The test case accurately reflects these settings, ensuring that omitted fields do not appear in the results and non-omitted fields are handled correctly.

  • packages/testtools/src/schema.ts: Correct application of prismaClientOptions.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the global settings for `omit` in Prisma client.

# Test: Search for global settings application. Expect: Correct application in client configurations.
rg --type python $'prismaClientOptions'

Length of output: 69



Script:

#!/bin/bash
# Description: Verify the global settings for `omit` in Prisma client.

# Test: Search for global settings application. Expect: Correct application in client configurations.
rg --type js,ts 'prismaClientOptions'

Length of output: 67



Script:

#!/bin/bash
# Description: Verify the global settings for `omit` in Prisma client.

# Test: Search for global settings application. Expect: Correct application in client configurations.
rg --type-add 'js:*.{js,jsx}' --type-add 'ts:*.{ts,tsx}' --type js --type ts 'prismaClientOptions'

Length of output: 457



Script:

#!/bin/bash
# Description: Verify the implementation of `prismaClientOptions` in the client configuration.

# Fetch lines around the usage of `prismaClientOptions` in `schema.ts` to ensure correct application.
rg --type ts --context 5 'prismaClientOptions' packages/testtools/src/schema.ts

Length of output: 871


Line range hint 4-57: Check for potential issues with dynamic schema loading and test logic.

The test case dynamically loads a schema and performs operations using Prisma. Ensure that all operations and expectations are correctly implemented and align with the intended use cases of the omit feature. Additionally, confirm that the schema provided matches the expected format and fields for the Prisma models being used.

packages/testtools/src/schema.ts (2)

137-137: Approve addition of prismaClientOptions in SchemaLoadOptions.

The addition of prismaClientOptions to SchemaLoadOptions is aligned with the PR objectives to enhance schema loading capabilities. This change allows for dynamic configuration of Prisma client options, which is essential for supporting different versions and features of Prisma.


259-263: Validate dynamic assignment of Prisma client options.

The logic for dynamically assigning Prisma client options based on provided settings appears correct. However, ensure that this functionality is covered by tests to prevent regressions or unexpected behaviors in future updates.

Verification successful

Test coverage for dynamic assignment of Prisma client options is adequate.

The test file tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts includes tests that cover the dynamic assignment of prismaClientOptions. This ensures that the functionality is being tested and helps prevent regressions or unexpected behaviors in future updates.

  • File: tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify dynamic assignment of Prisma client options.

# Test: Search for test coverage of dynamic assignment. Expect: Adequate test coverage.
rg --type python $'prismaClientOptions'

Length of output: 69



Script:

#!/bin/bash
# Description: Verify dynamic assignment of Prisma client options in TypeScript test files.

# Test: Search for test coverage of dynamic assignment. Expect: Adequate test coverage.
rg --type ts 'prismaClientOptions'

Length of output: 393



Script:

#!/bin/bash
# Display the content of the test file that references `prismaClientOptions` to verify test coverage.

cat tests/integration/tests/enhancements/with-policy/prisma-omit.test.ts

Length of output: 3642

@ymc9 ymc9 merged commit 0a293ca into dev Jun 28, 2024
13 checks passed
@ymc9 ymc9 deleted the fix/prisma-5.16.0 branch June 28, 2024 00:59
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