Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented Jul 18, 2025

Create ContentVariant type, add as a column in Content table (and corresponding input type)
Handle in upsert function.

Summary by CodeRabbit

  • New Features

    • Introduced a new content variant option, allowing content to be categorized as "direct", "direct_and_children", or "direct_and_description".
    • Added a "variant" field to content records, enabling more granular distinction and handling of content types.
  • Refactor

    • Updated default value formatting for improved consistency.
    • Adjusted the order of some function arguments for greater consistency across the platform.

@linear
Copy link

linear bot commented Jul 18, 2025

@supabase
Copy link

supabase bot commented Jul 18, 2025

Updates to Preview Branch (ENG-587-mark-content-variants) ↗︎

Deployments Status Updated
Database Fri, 18 Jul 2025 13:55:40 UTC
Services Fri, 18 Jul 2025 13:55:40 UTC
APIs Fri, 18 Jul 2025 13:55:40 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Fri, 18 Jul 2025 13:55:48 UTC
Migrations Fri, 18 Jul 2025 13:55:49 UTC
Seeding Fri, 18 Jul 2025 13:55:49 UTC
Edge Functions Fri, 18 Jul 2025 13:55:49 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@maparent
Copy link
Collaborator Author

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 18, 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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 18, 2025

📝 Walkthrough

Walkthrough

A new enum ContentVariant with values direct, direct_and_children, and direct_and_description was introduced and integrated into the Content table, related composite types, and the upsert_content function. The unique index on the Content table was updated to include the variant column. Default value string literals in the schema were standardized to use double quotes.

Changes

Files/Paths Change Summary
packages/database/schema.yaml Added ContentVariant enum; updated default string literals from single to double quotes in slot definitions.
packages/database/supabase/migrations/20250718131540_content_variant.sql,
packages/database/supabase/schemas/content.sql
Added ContentVariant enum and variant column to Content table; updated unique index; modified upsert_content function and composite type to handle variant.
packages/database/types.gen.ts Added variant field to Content types and composite types; introduced ContentVariant enum; reordered arguments in several function type definitions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DB
    participant upsert_content_fn as upsert_content (DB Function)

    Client->>DB: Call upsert_content(space_id, data, creator_id, content_as_document)
    DB->>upsert_content_fn: Process each content item in data
    upsert_content_fn->>DB: Upsert Document (if needed)
    upsert_content_fn->>DB: Upsert Content (space_id, source_local_id, variant)
    alt Embedding specified
        upsert_content_fn->>DB: upsert_content_embedding(content_id, model, vector)
    end
    upsert_content_fn-->>Client: Return upserted content IDs
Loading

Possibly related PRs

  • DiscourseGraphs/discourse-graph#202: Updates to the upsert_content function and related schema for bulk content upsert, which this PR extends by adding the ContentVariant enum and modifying relevant database structures and logic.

📜 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 59557e7 and 0cc39ab.

📒 Files selected for processing (4)
  • packages/database/schema.yaml (6 hunks)
  • packages/database/supabase/migrations/20250718131540_content_variant.sql (1 hunks)
  • packages/database/supabase/schemas/content.sql (8 hunks)
  • packages/database/types.gen.ts (12 hunks)
🧰 Additional context used
🧠 Learnings (4)
packages/database/schema.yaml (4)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/schema.yaml:0-0
Timestamp: 2025-06-09T16:53:13.253Z
Learning: In LinkML schema files, enum default values should use the enum constructor syntax like `ifabsent: AgentType(person)` rather than literal string values like `ifabsent: 'person'`. This is the correct syntax that passes LinkML linting.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/schema.yaml:116-121
Timestamp: 2025-05-20T03:06:16.600Z
Learning: In the discourse-graph project's LinkML schema (packages/database/schema.yaml), attributes and slots are equivalent constructs. Items can be defined either as slots or attributes without needing to duplicate them in both sections.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/schema.yaml:143-143
Timestamp: 2025-06-04T11:40:30.149Z
Learning: In the DiscourseGraphs project, linkml-lint requires string representations for default values in LinkML schema YAML files (e.g., 'true', 'false', '0') rather than native YAML types, despite LinkML documentation suggesting native types.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250513173724_content_concept_key.sql:37-60
Timestamp: 2025-05-22T23:50:23.771Z
Learning: For the discourse-graph project, database schema management focuses on the final state in the supabase/schemas directory, not on the individual migration files. When reviewing database changes, consider only the schema definitions in this directory, not potential duplications or conflicts across migration files.
packages/database/supabase/schemas/content.sql (8)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/schemas/extensions.sql:1-11
Timestamp: 2025-05-20T03:02:36.027Z
Learning: The necessary schemas for Supabase extensions (like 'extensions', 'graphql', and 'vault') are automatically created by Supabase before extensions are installed, so they don't need to be explicitly created in SQL migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250513173724_content_concept_key.sql:37-60
Timestamp: 2025-05-22T23:50:23.771Z
Learning: For the discourse-graph project, database schema management focuses on the final state in the supabase/schemas directory, not on the individual migration files. When reviewing database changes, consider only the schema definitions in this directory, not potential duplications or conflicts across migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/supabase/migrations/20250605083319_alpha_upload.sql:157-337
Timestamp: 2025-06-09T16:57:14.681Z
Learning: Migration files in packages/database/supabase/migrations/ are historical snapshots that preserve database schema and functions as they existed at the time of creation. These files should not be updated to reflect current schema changes, even if they reference tables or columns that have since been modified or removed. Schema incompatibilities in migration files are expected and acceptable as they represent the valid state at the time of migration.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504195841_remote_schema.sql:1-7
Timestamp: 2025-05-20T03:01:11.220Z
Learning: Supabase automatically creates necessary schemas like the "extensions" schema before migrations run, so there's no need to explicitly create these schemas in migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504202930_content_tables.sql:37-45
Timestamp: 2025-05-20T03:11:07.917Z
Learning: When reviewing SQL migrations in this codebase, understand that historical migration files should not be modified once they're applied. Instead, issues should be fixed in subsequent migrations or schema definition files. This is why maparent indicated "migration, not changing. corrected in schema."
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-13T16:47:14.352Z
Learning: When reviewing SQL functions in the discourse-graph codebase, be mindful that suggesting additional explicit error handling may introduce unnecessary database queries. Functions that use appropriate ON CONFLICT clauses may already handle errors sufficiently without needing extra validation queries.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-06-07T02:56:57.093Z
Learning: In the discourse-graph project's upsert_content function, null creator_id values are tolerated as an acceptable trade-off, even though they may be annoying, rather than failing the entire operation.
packages/database/supabase/migrations/20250718131540_content_variant.sql (9)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/supabase/migrations/20250605083319_alpha_upload.sql:157-337
Timestamp: 2025-06-09T16:57:14.681Z
Learning: Migration files in packages/database/supabase/migrations/ are historical snapshots that preserve database schema and functions as they existed at the time of creation. These files should not be updated to reflect current schema changes, even if they reference tables or columns that have since been modified or removed. Schema incompatibilities in migration files are expected and acceptable as they represent the valid state at the time of migration.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504202930_content_tables.sql:37-45
Timestamp: 2025-05-20T03:11:07.917Z
Learning: When reviewing SQL migrations in this codebase, understand that historical migration files should not be modified once they're applied. Instead, issues should be fixed in subsequent migrations or schema definition files. This is why maparent indicated "migration, not changing. corrected in schema."
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504202930_content_tables.sql:37-45
Timestamp: 2025-05-20T03:11:07.917Z
Learning: When reviewing SQL migrations in the discourse-graph codebase, understand that historical migration files should not be modified once they're applied. Instead, issues should be fixed in subsequent migrations or schema definition files. This is why maparent indicated "migration, not changing. corrected in schema."
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/schemas/extensions.sql:1-11
Timestamp: 2025-05-20T03:02:36.027Z
Learning: The necessary schemas for Supabase extensions (like 'extensions', 'graphql', and 'vault') are automatically created by Supabase before extensions are installed, so they don't need to be explicitly created in SQL migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504195841_remote_schema.sql:1-7
Timestamp: 2025-05-20T03:01:11.220Z
Learning: Supabase automatically creates necessary schemas like the "extensions" schema before migrations run, so there's no need to explicitly create these schemas in migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-06-07T02:56:57.093Z
Learning: In the discourse-graph project's upsert_content function, null creator_id values are tolerated as an acceptable trade-off, even though they may be annoying, rather than failing the entire operation.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:38.048Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.
packages/database/types.gen.ts (5)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-13T16:47:14.352Z
Learning: In the discourse-graph codebase, types.gen.ts contains automatically generated database function type definitions that may have reordered signatures between versions. This reordering is expected behavior from the code generation process and should not be flagged as an issue requiring fixes.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:38.048Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-06-07T02:56:57.093Z
Learning: In the discourse-graph project's upsert_content function, null creator_id values are tolerated as an acceptable trade-off, even though they may be annoying, rather than failing the entire operation.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Supabase Preview
🔇 Additional comments (11)
packages/database/schema.yaml (2)

25-30: Well-structured ContentVariant enum addition.

The new ContentVariant enum is clearly defined with logical values that distinguish between different content processing modes. The description accurately explains the purpose.


148-148: Consistent quote standardization aligns with LinkML requirements.

The standardization from single quotes to double quotes for default string values is consistent with the retrieved learning about LinkML linting requirements for string representations in YAML files.

Also applies to: 156-156, 179-179, 307-307, 327-327, 336-336, 341-341, 345-345, 454-454, 460-460

packages/database/supabase/schemas/content.sql (4)

16-22: ContentVariant enum correctly implemented.

The enum creation with proper ownership assignment follows standard PostgreSQL practices.


79-79: Proper schema integration of variant field.

The variant column addition with appropriate default, the updated unique index to include variant, and the composite type extension are all correctly implemented and maintain data integrity.

Also applies to: 131-133, 190-190


454-454: upsert_content function properly handles variant field.

The function correctly includes the variant field in the INSERT statement, uses appropriate COALESCE for default values, and updates the ON CONFLICT clause to match the new unique index constraint.

Also applies to: 467-467, 472-472, 478-478


522-522: Row-level security policies formatting improvement.

The removal of spaces inside the public.in_space() function calls improves code consistency.

Also applies to: 527-527

packages/database/supabase/migrations/20250718131540_content_variant.sql (3)

1-8: ContentVariant enum creation follows PostgreSQL standards.

The enum creation with proper ownership assignment is correctly implemented.


9-15: Proper table schema evolution with index recreation.

The variant column addition and the approach of dropping and recreating the unique index to include the variant field is the correct way to evolve the schema while maintaining data integrity.


17-137: Comprehensive upsert_content function implementation.

The function correctly handles the new variant field throughout the upsert process, includes proper COALESCE usage for metadata fields, and updates the conflict resolution to use the new unique constraint.

packages/database/types.gen.ts (2)

200-200: Complete TypeScript type integration for ContentVariant.

The type definitions properly reflect the database schema changes with the ContentVariant enum, variant field in Content table types, composite type updates, and function return types. All changes are consistent and maintain type safety.

Also applies to: 215-215, 230-230, 553-553, 745-748, 841-841, 976-980


607-616: Expected function signature reordering from code generation.

The reordering of function argument types is expected behavior from the automatic code generation process and doesn't affect functionality.

Also applies to: 635-641, 648-654, 687-695, 700-703, 713-716, 737-740


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 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 maparent requested a review from mdroidian July 18, 2025 14:01
@mdroidian mdroidian merged commit 9af2ee7 into main Jul 19, 2025
3 checks passed
@mdroidian mdroidian deleted the ENG-587-mark-content-variants branch July 19, 2025 23:45
@github-project-automation github-project-automation bot moved this to Done in General Jul 19, 2025
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