Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Jun 9, 2025

Summary by CodeRabbit

  • New Features

    • Added comprehensive support for many-to-many relations, including creation, querying, updating, and deletion across SQLite and PostgreSQL.
    • Introduced a new property to access the raw query builder instance.
    • Added support for named relations in schema generation and TypeScript output.
    • Enabled auto-increment field handling for SQLite and PostgreSQL.
  • Bug Fixes

    • Improved handling of boolean filters in query conditions.
  • Tests

    • Added extensive integration tests for all relation types, including many-to-many and named relations.
  • Chores

    • Updated dependencies and configuration files for improved development workflow.
    • Enhanced test utilities with new options for schema application.

@coderabbitai
Copy link

coderabbitai bot commented Jun 9, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces comprehensive support for many-to-many (m2m) relations across the runtime, including query building, CRUD operations, and schema handling. It also adds support for named relations, enhances auto-increment field handling for SQLite and PostgreSQL, and updates test infrastructure and documentation. New integration tests validate relational behaviors for various database providers.

Changes

File(s) Change Summary
TODO.md Updated task statuses, added/removed tasks in ORM, Misc, and Access Policy sections.
packages/cli/src/actions/generate.ts, packages/sdk/src/index.ts Consolidated and updated imports/exports for PrismaSchemaGenerator from the SDK package.
packages/cli/test/ts-schema-gen.test.ts, packages/runtime/test/policy/todo-sample.test.ts Adjusted test code to destructure schema from generateTsSchema/generateTsSchemaFromFile return values.
packages/runtime/package.json, packages/testtools/package.json Added new dependencies: @zenstackhq/sdk (dev) and prisma (runtime) respectively.
packages/runtime/src/client/client-impl.ts, packages/runtime/src/client/contract.ts Added $qbRaw property to client implementation and contract for raw Kysely access.
packages/runtime/src/client/crud/dialects/base.ts Added boolean filter support and explicit many-to-many relation handling in filter and relation filter building.
packages/runtime/src/client/crud/dialects/postgresql.ts, packages/runtime/src/client/crud/dialects/sqlite.ts Added many-to-many relation support in relation JSON building for PostgreSQL and SQLite dialects.
packages/runtime/src/client/crud/operations/base.ts Extended CRUD operation handler for comprehensive many-to-many relation support across create, update, connect, disconnect, etc.
packages/runtime/src/client/helpers/schema-db-pusher.ts Added auto-increment field support for SQLite and PostgreSQL in schema-to-DB mapping.
packages/runtime/src/client/query-utils.ts Added getManyToManyRelation utility to detect and describe many-to-many relations in schema.
packages/runtime/src/schema/schema.ts Extended RelationInfo type with optional name property for named relations.
packages/runtime/test/client-api/relation.test.ts Added extensive integration tests for one-to-one, one-to-many, and many-to-many relations (named/unnamed, explicit/implicit).
packages/runtime/test/utils.ts Refactored test client creation; added usePrismaPush option for schema application via Prisma CLI.
packages/sdk/src/prisma/prisma-schema-generator.ts Updated import paths for ModelUtils and ZModelCodeGenerator.
packages/sdk/src/ts-schema-generator.ts Added support for named relations in TypeScript schema generator, including relation name extraction and matching.
packages/sdk/tsconfig.json Excluded test files from TypeScript compilation.
packages/testtools/src/schema.ts Adjusted SQLite datasource URL to use dbName parameter; changed generateTsSchema return value to include workDir and schema.
samples/blog/zenstack/schema.ts Removed explicit return type annotation from dialectConfigProvider function.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ClientImpl
    participant BaseOperationHandler
    participant QueryUtils
    participant DB

    User->>ClientImpl: create/update/connect/disconnect/set/delete (with m2m relation)
    ClientImpl->>BaseOperationHandler: invoke operation handler
    BaseOperationHandler->>QueryUtils: getManyToManyRelation(schema, model, field)
    QueryUtils-->>BaseOperationHandler: m2m relation metadata (if applicable)
    alt is many-to-many
        BaseOperationHandler->>DB: insert/delete into join table as needed
    else not many-to-many
        BaseOperationHandler->>DB: update foreign keys as usual
    end
    BaseOperationHandler-->>ClientImpl: operation result
    ClientImpl-->>User: result
Loading

Poem

A bunny hops through fields of code,
Where many-to-many relations now smoothly flow’d.
Named ties and joins, all handled with care,
Auto-increment fields pop up everywhere!
With tests that ensure the links never break,
This rabbit’s release is a joy to make.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7537e1e and 3468960.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (23)
  • TODO.md (2 hunks)
  • packages/cli/src/actions/generate.ts (1 hunks)
  • packages/cli/test/ts-schema-gen.test.ts (1 hunks)
  • packages/runtime/package.json (1 hunks)
  • packages/runtime/src/client/client-impl.ts (5 hunks)
  • packages/runtime/src/client/contract.ts (1 hunks)
  • packages/runtime/src/client/crud/dialects/base.ts (4 hunks)
  • packages/runtime/src/client/crud/dialects/postgresql.ts (2 hunks)
  • packages/runtime/src/client/crud/dialects/sqlite.ts (2 hunks)
  • packages/runtime/src/client/crud/operations/base.ts (11 hunks)
  • packages/runtime/src/client/helpers/schema-db-pusher.ts (3 hunks)
  • packages/runtime/src/client/query-utils.ts (1 hunks)
  • packages/runtime/src/schema/schema.ts (1 hunks)
  • packages/runtime/test/client-api/relation.test.ts (1 hunks)
  • packages/runtime/test/policy/todo-sample.test.ts (1 hunks)
  • packages/runtime/test/utils.ts (3 hunks)
  • packages/sdk/src/index.ts (1 hunks)
  • packages/sdk/src/prisma/prisma-schema-generator.ts (1 hunks)
  • packages/sdk/src/ts-schema-generator.ts (2 hunks)
  • packages/sdk/tsconfig.json (1 hunks)
  • packages/testtools/package.json (1 hunks)
  • packages/testtools/src/schema.ts (3 hunks)
  • samples/blog/zenstack/schema.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

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