Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented Jun 16, 2025

Summary by CodeRabbit

  • New Features
    • The "arity" value in concepts is now automatically calculated based on content, ensuring it always reflects the latest roles information.
  • Bug Fixes
    • Improved extraction of references to prevent duplicate entries in results.

@linear
Copy link

linear bot commented Jun 16, 2025

@vercel
Copy link

vercel bot commented Jun 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
discourse-graph ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2025 0:25am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 16, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This change updates the "Concept" table by redefining the "arity" column as a generated stored column, computed dynamically using new SQL functions that count elements in a JSONB "roles" array. It also updates the extract_references function to return distinct values and introduces three new helper functions for arity calculation.

Changes

File(s) Change Summary
.../migrations/20250616212706_generate-arity.sql Drops and re-adds the "arity" column as a generated stored column; creates/replaces functions for arity computation and reference extraction.
.../schemas/concept.sql Updates extract_references to return distinct values; adds compute_arity_lit, compute_arity_id, and compute_arity_local; modifies "arity" column to be generated.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Database
    participant compute_arity_local
    participant compute_arity_id
    participant compute_arity_lit

    Client->>Database: Insert/Update Concept row
    Database->>compute_arity_local: compute_arity_local(schema_id, literal_content)
    alt schema_id is not null
        compute_arity_local->>compute_arity_id: compute_arity_id(schema_id)
        compute_arity_id-->>compute_arity_local: arity count
    else schema_id is null
        compute_arity_local->>compute_arity_lit: compute_arity_lit(literal_content)
        compute_arity_lit-->>compute_arity_local: arity count
    end
    compute_arity_local-->>Database: arity value
    Database-->>Client: Row with computed arity
Loading

Possibly related PRs

Poem

In the warren of data, new columns appear,
Arity now counts, with logic so clear.
Functions hop in, to tally each role,
And references gathered, distinct as a goal.
With SQL so clever, the schema takes flight—
A rabbit’s delight in the database night! 🐇


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.

@maparent
Copy link
Collaborator Author

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 16, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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 (7)
packages/database/supabase/schemas/concept.sql (4)

16-17: Ensure robust JSON parsing and uniqueness in extract_references.

The use of jsonb_path_query_array with DISTINCT handles duplicates, but you may want to guard against unexpected JSON structures or non-numeric values causing cast errors. Consider validating with jsonb_typeof before casting or falling back gracefully when invalid.


19-21: Optimize arity calculation with jsonb_array_length.

Extracting each element into a CTE and counting can be simplified and accelerated using:

SELECT COALESCE(jsonb_array_length(lit_content->'roles'), 0);

This reduces overhead and improves readability.


23-27: Avoid per-row subquery overhead in compute_arity_id.

Querying public."Concept" inside this function for every invocation could become a performance bottleneck on large tables. Consider passing pre-fetched JSONB or computing role counts via triggers/materialized views to eliminate the on-the-fly lookup.


29-31: Add null/empty handling for compute_arity_local.

If literal_content is ever null or missing the roles key, the function may error. Wrapping with COALESCE(lit_content, '{}'::jsonb) and coalescing the result to zero will prevent unexpected failures.

packages/database/supabase/migrations/20250616212706_generate-arity.sql (3)

5-11: Refactor compute_arity_id for clarity and performance.

Instead of iterating with jsonb_path_query, you can use:

SELECT COALESCE(jsonb_array_length(literal_content->'roles'), 0)
  FROM public."Concept" WHERE id = p_schema_id;

This streamlines the function and reduces CTE overhead.


13-19: Simplify compute_arity_lit using direct array length.

Replace the CTE approach with:

SELECT COALESCE(jsonb_array_length(lit_content->'roles'), 0);

This keeps immutability and lowers execution cost.


21-27: Harden compute_arity_local with defensive defaults.

Wrap lit_content in COALESCE(lit_content, '{}'::jsonb) and handle missing schema rows explicitly (e.g., return 0 if no concept found) to avoid null or lookup errors.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d0afedb and 61c2ff9.

📒 Files selected for processing (2)
  • packages/database/supabase/migrations/20250616212706_generate-arity.sql (1 hunks)
  • packages/database/supabase/schemas/concept.sql (2 hunks)
🔇 Additional comments (3)
packages/database/supabase/schemas/concept.sql (2)

45-45: Verify backfill of generated arity column.

Dropping and re-adding this column will backfill based on existing data—add a sanity query or test post-migration to confirm there are no nulls or miscounts.


49-49: Generated refs column implementation looks solid.

Using DISTINCT and COALESCE ensures duplicate elimination and empty-array handling, and the GIN index on refs should preserve query performance.

packages/database/supabase/migrations/20250616212706_generate-arity.sql (1)

29-35: extract_references definition matches schema file.

The migration’s CREATE OR REPLACE FUNCTION is consistent with the schema and indexing strategy; no changes needed here.

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

👍

@mdroidian
Copy link
Contributor

I'm curious why this is merging into ENG-446-bulk-db-concept-upsert instead of main.

@maparent
Copy link
Collaborator Author

Actually, good point; it was because the change was prompted by a coderabbit comment on 446. But no reason not to rebase on main.

@maparent maparent force-pushed the ENG-463-autogenerate-arity branch from 54109b2 to 3a7d7ed Compare June 18, 2025 00:23
@maparent maparent changed the base branch from ENG-446-bulk-db-concept-upsert to main June 18, 2025 00:25
@maparent maparent merged commit 9504ec5 into main Jun 18, 2025
3 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Jun 18, 2025
@maparent maparent deleted the ENG-463-autogenerate-arity branch June 18, 2025 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants