Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Jun 1, 2025

Summary by CodeRabbit

  • New Features

    • Added utility functions to simplify database configuration for PostgreSQL and SQLite.
    • Improved support for array-typed fields in validation and database operations.
  • Bug Fixes

    • Enhanced policy enforcement logic to handle both raw and AST values for field comparisons.
    • Corrected handling of grouping and aggregation in queries.
  • Documentation

    • Updated usage examples to reflect new client instantiation and configuration methods.
  • Refactor

    • Unified and modularized handling of database providers and schema generation.
    • Streamlined test setup and improved configuration flexibility for test clients.
  • Tests

    • Added comprehensive tests for empty policies and field comparison scenarios.
    • Improved test reliability by centralizing schema synchronization logic.
  • Chores

    • Updated dependencies and build configuration to include new utilities.

@coderabbitai
Copy link

coderabbitai bot commented Jun 1, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces new utility modules for PostgreSQL and SQLite dialect configuration, refines policy enforcement and expression transformation logic, and enhances test infrastructure for flexible provider and schema management. It also updates validation, client instantiation examples, and test suites, especially regarding schema handling and provider-specific behaviors.

Changes

File(s) / Group Change Summary
packages/runtime/src/utils/pg-utils.ts, packages/runtime/src/utils/sqlite-utils.ts Added utility functions for generating Kysely dialect configs for PostgreSQL and SQLite.
packages/runtime/package.json, packages/runtime/tsup.config.ts Added exports and build entries for new utility modules; added pg-connection-string dependency.
packages/sdk/src/ts-schema-generator.ts Refactored provider handling, imports, and dialect config generation for both SQLite and PostgreSQL.
packages/testtools/src/schema.ts Made datasource prelude dynamic, updated generateTsSchema to accept provider/dbName, and used pattern matching.
packages/runtime/test/utils.ts Centralized PG config, enforced schema push after client creation, and improved provider/dbName handling.
packages/runtime/test/client-api/client-specs.ts Allowed selective provider inclusion, updated function signatures, and improved client creation logic.
packages/runtime/test/policy/utils.ts Updated type for options parameter to new CreateTestClientOptions.
packages/runtime/src/client/crud/dialects/base.ts Added abstract buildArrayLiteralSQL method to BaseCrudDialect.
packages/runtime/src/client/crud/dialects/postgresql.ts, packages/runtime/src/client/crud/dialects/sqlite.ts Implemented/overrode buildArrayLiteralSQL for PostgreSQL and SQLite.
packages/runtime/src/client/crud/validator.ts Improved array field validation and refined groupBy schema refinement logic.
packages/runtime/src/client/executor/name-mapper.ts Ensured select-all expansions use mapped table names.
packages/runtime/src/client/helpers/schema-db-pusher.ts Improved array type handling for Kysely column data types.
packages/language/src/validators/datamodel-validator.ts Disallowed array types for non-data models on SQLite; added provider extraction logic.
packages/runtime/src/plugins/policy/expression-transformer.ts Updated context types, improved 'in' operator handling, and argument transformation logic.
packages/runtime/src/plugins/policy/policy-handler.ts Refactored to handle both OperationNode and raw values in policy enforcement.
samples/blog/README.md, packages/cli/src/actions/generate.ts Updated example code to use ZenStackClient instead of createClient.
samples/blog/zenstack/schema.ts Switched to using new SQLite dialect config utility.
packages/testtools/package.json Added ts-pattern dependency.
packages/runtime/test/client-api/*.test.ts (multiple files) Removed client.$pushSchema() from test setup to rely on new schema push logic.
packages/runtime/test/policy/empty-policy.test.ts, packages/runtime/test/policy/field-comparison.test.ts Added new test suites for empty policy and field comparison scenarios.
TODO.md Marked "Aggregation" as complete and added two new ORM tasks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ZenStackClient
    participant toDialectConfig (PG/SQLite)
    participant DB

    User->>ZenStackClient: Instantiate with schema
    ZenStackClient->>toDialectConfig (PG/SQLite): Get dialect config (provider-specific)
    toDialectConfig (PG/SQLite)->>DB: Create DB connection/config
    DB-->>toDialectConfig (PG/SQLite): Return config
    toDialectConfig (PG/SQLite)-->>ZenStackClient: Return dialect config
    ZenStackClient-->>User: Ready client instance
Loading
sequenceDiagram
    participant Client
    participant PolicyHandler
    participant ExpressionTransformer

    Client->>PolicyHandler: Create mutation with values
    PolicyHandler->>PolicyHandler: Split values into OperationNode and raw
    PolicyHandler->>ExpressionTransformer: Transform policy condition with both representations
    ExpressionTransformer-->>PolicyHandler: Return transformed condition
    PolicyHandler-->>Client: Proceed with policy-enforced operation
Loading

Possibly related PRs

  • zenstackhq/zenstack-v3#3: Updates policy enforcement and expression transformation logic, similar to this PR's changes in policy handler and expression transformer context.

Poem

A rabbit hopped through code so neat,
Dialects for DBs—what a treat!
Policies checked with values raw,
Array types handled without a flaw.
Tests now smarter, setup clean,
With utilities new and logic keen.
🐇✨ Hooray for code that runs serene!


📜 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 9896d69 and 1b0569b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (40)
  • TODO.md (2 hunks)
  • packages/cli/src/actions/generate.ts (1 hunks)
  • packages/language/src/validators/datamodel-validator.ts (3 hunks)
  • packages/runtime/package.json (2 hunks)
  • packages/runtime/src/client/crud/dialects/base.ts (1 hunks)
  • packages/runtime/src/client/crud/dialects/postgresql.ts (1 hunks)
  • packages/runtime/src/client/crud/dialects/sqlite.ts (1 hunks)
  • packages/runtime/src/client/crud/validator.ts (3 hunks)
  • packages/runtime/src/client/executor/name-mapper.ts (1 hunks)
  • packages/runtime/src/client/helpers/schema-db-pusher.ts (2 hunks)
  • packages/runtime/src/plugins/policy/expression-transformer.ts (3 hunks)
  • packages/runtime/src/plugins/policy/policy-handler.ts (10 hunks)
  • packages/runtime/src/utils/pg-utils.ts (1 hunks)
  • packages/runtime/src/utils/sqlite-utils.ts (1 hunks)
  • packages/runtime/test/client-api/aggregate.test.ts (1 hunks)
  • packages/runtime/test/client-api/client-specs.ts (2 hunks)
  • packages/runtime/test/client-api/count.test.ts (0 hunks)
  • packages/runtime/test/client-api/create-many-and-return.test.ts (0 hunks)
  • packages/runtime/test/client-api/create-many.test.ts (0 hunks)
  • packages/runtime/test/client-api/create.test.ts (0 hunks)
  • packages/runtime/test/client-api/delete-many.test.ts (0 hunks)
  • packages/runtime/test/client-api/delete.test.ts (0 hunks)
  • packages/runtime/test/client-api/filter.test.ts (0 hunks)
  • packages/runtime/test/client-api/find.test.ts (0 hunks)
  • packages/runtime/test/client-api/group-by.test.ts (3 hunks)
  • packages/runtime/test/client-api/update-many.test.ts (0 hunks)
  • packages/runtime/test/client-api/update.test.ts (0 hunks)
  • packages/runtime/test/client-api/upsert.test.ts (0 hunks)
  • packages/runtime/test/policy/auth.test.ts (1 hunks)
  • packages/runtime/test/policy/empty-policy.test.ts (1 hunks)
  • packages/runtime/test/policy/field-comparison.test.ts (1 hunks)
  • packages/runtime/test/policy/read.test.ts (0 hunks)
  • packages/runtime/test/policy/utils.ts (1 hunks)
  • packages/runtime/test/utils.ts (3 hunks)
  • packages/runtime/tsup.config.ts (1 hunks)
  • packages/sdk/src/ts-schema-generator.ts (8 hunks)
  • packages/testtools/package.json (1 hunks)
  • packages/testtools/src/schema.ts (2 hunks)
  • samples/blog/README.md (1 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.

@ymc9 ymc9 merged commit 7ecbe4c into dev Jun 1, 2025
1 check passed
@coderabbitai coderabbitai bot mentioned this pull request Jun 28, 2025
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