Skip to content

Enable JSON fields for SQLite #2081

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

Merged
merged 23 commits into from
Apr 14, 2025
Merged

Conversation

liontariai
Copy link
Contributor

It's supported by prisma according to the docs https://www.prisma.io/docs/orm/reference/prisma-schema-reference#json
and I've been using it in my private projects for some time now by patching zenstack.

Also, here's the Prisma release announcing the feature: https://github.com/prisma/prisma/releases/tag/6.2.0

I was hoping for this to come to zenstack naturally but it seems to still be overlooked.

It's really just this one line, so I haven't run a testsuite or written tests for it.
I'm open to feedback as this is my first PR here, but I think it's really not worth putting too much overhead-effort into this one.

Copy link
Contributor

coderabbitai bot commented Apr 13, 2025

📝 Walkthrough

Walkthrough

The pull request updates the constant PROVIDERS_SUPPORTING_TYPEDEF_FIELDS in the Prisma schema generator. Originally, this constant only included 'postgresql'. The change adds 'sqlite', which expands support for typedef fields to include SQLite databases. Additionally, the test suites for JSON field CRUD operations, typing, and validation have been modified to support both PostgreSQL and SQLite, enhancing the flexibility of the tests by parameterizing the database provider.

Changes

File(s) Change Summary
packages/schema/.../schema-generator.ts Updated the PROVIDERS_SUPPORTING_TYPEDEF_FIELDS constant from ['postgresql'] to ['postgresql', 'sqlite'].
tests/integration/tests/enhancements/json/crud.test.ts Updated test suite to use describe.each for both SQLite and PostgreSQL, replacing hardcoded provider strings with a variable.
tests/integration/tests/enhancements/json/typing.test.ts Updated test suite to use describe.each for both SQLite and PostgreSQL, replacing hardcoded provider strings with a variable.
tests/integration/tests/enhancements/json/validation.test.ts Removed test case that checked for @json attribute support in PostgreSQL only.

📜 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 9288755 and 262316f.

📒 Files selected for processing (3)
  • tests/integration/tests/enhancements/json/crud.test.ts (11 hunks)
  • tests/integration/tests/enhancements/json/typing.test.ts (9 hunks)
  • tests/integration/tests/enhancements/json/validation.test.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/integration/tests/enhancements/json/validation.test.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/integration/tests/enhancements/json/crud.test.ts (1)
packages/testtools/src/db.ts (2)
  • createPostgresDb (19-25)
  • dropPostgresDb (27-31)
🔇 Additional comments (7)
tests/integration/tests/enhancements/json/typing.test.ts (2)

3-3: Excellent parameterization of tests to include SQLite support!

This change effectively parameterizes the test suite to run against both SQLite and PostgreSQL, aligning with the PR objective to enable JSON fields for SQLite.


26-26: LGTM: Properly parameterized provider configuration

All test cases now correctly use the dynamic provider parameter instead of the hardcoded 'postgresql', enabling the tests to run seamlessly with both database types.

Also applies to: 67-67, 108-108, 154-154, 206-206, 255-255, 306-306, 351-351

tests/integration/tests/enhancements/json/crud.test.ts (5)

3-3: Well-structured test parameterization for multi-database support

The test suite is now properly configured to run against both SQLite and PostgreSQL databases using the describe.each pattern, which is a clean approach for parameterized testing.


8-10: Correct conditional database creation logic

The conditional database creation for PostgreSQL only is appropriate since SQLite doesn't require the same setup process. This prevents unnecessary operations when testing with SQLite.


14-19: Appropriate conditional cleanup for PostgreSQL

The cleanup logic is correctly conditioned to only run for PostgreSQL, ensuring that database resources are properly managed without attempting to drop non-existent resources when using SQLite.


48-48: LGTM: Consistent provider parameterization throughout test cases

All test cases now correctly use the dynamic provider parameter instead of hardcoded values, ensuring consistent behavior across different database backends.

Also applies to: 97-97, 144-144, 218-218, 262-262, 298-298, 335-335, 375-375, 408-408, 453-453


1-498:

✅ Verification successful

Verify the implementation in schema-generator.ts

While the test changes look good, we should verify that the actual implementation to enable JSON fields for SQLite is present in the schema generator code.


🏁 Script executed:

#!/bin/bash
# Find the PROVIDERS_SUPPORTING_TYPEDEF_FIELDS constant in schema-generator.ts
rg "PROVIDERS_SUPPORTING_TYPEDEF_FIELDS" -A 5 packages/schema/src/plugins/prisma/schema-generator.ts

Length of output: 726


SQLite JSON Fields Support Verified in Schema Generator

I verified that the constant PROVIDERS_SUPPORTING_TYPEDEF_FIELDS in packages/schema/src/plugins/prisma/schema-generator.ts includes both 'postgresql' and 'sqlite'. This confirms that JSON field support for SQLite is indeed enabled, and no further changes are required.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 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 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 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 changed the base branch from main to dev April 13, 2025 22:07
@ymc9
Copy link
Member

ymc9 commented Apr 14, 2025

Hi @liontariai , thanks for making this PR! I've fixed a broken test case and also added test coverage for sqlite+json. Will merge it when CI passes.

@ymc9 ymc9 merged commit 22db7b5 into zenstackhq:dev Apr 14, 2025
11 of 12 checks passed
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