Skip to content

Conversation

sid597
Copy link
Collaborator

@sid597 sid597 commented Aug 3, 2025

image

Summary by CodeRabbit

  • Bug Fixes

    • Removed several outdated database functions related to content synchronization, embedding matching, and discourse node management.
    • Cleaned up associated configuration and type definitions to reflect these removals.
  • Chores

    • Updated database schema and migration scripts to ensure deprecated functions are fully dropped.

These changes streamline the database and remove unused or obsolete features, improving maintainability. No user-facing features or workflows are affected.

Copy link

linear bot commented Aug 3, 2025

Copy link

supabase bot commented Aug 3, 2025

Updates to Preview Branch (eng-450-remove-unused-db-functions) ↗︎

Deployments Status Updated
Database Sun, 10 Aug 2025 08:06:35 UTC
Services Sun, 10 Aug 2025 08:06:35 UTC
APIs Sun, 10 Aug 2025 08:06:35 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 Sun, 10 Aug 2025 08:06:37 UTC
Migrations Sun, 10 Aug 2025 08:06:37 UTC
Seeding Sun, 10 Aug 2025 08:06:37 UTC
Edge Functions Sun, 10 Aug 2025 08:06:40 UTC

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

@sid597
Copy link
Collaborator Author

sid597 commented Aug 3, 2025

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Aug 3, 2025

✅ Actions performed

Full review triggered.

Copy link
Contributor

coderabbitai bot commented Aug 3, 2025

📝 Walkthrough

Walkthrough

This change removes multiple legacy PostgreSQL functions and their associated type declarations related to discourse node upsert, synchronization, and embedding similarity search from the database schema, migration scripts, and generated TypeScript types. The schema file containing these functions is deleted, and references to it are removed from configuration.

Changes

Cohort / File(s) Change Summary
Migration scripts for function removal
packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql, packages/database/supabase/migrations/20250803100134_drop-get_nodes_needing_sync.sql
Adds migration scripts to drop six legacy functions (alpha_delete_by_source_local_ids, alpha_get_last_update_time, alpha_upsert_discourse_nodes, match_content_embeddings, upsert_discourse_nodes, get_nodes_needing_sync) from the public schema if they exist.
Schema file deletions and modifications
packages/database/supabase/schemas/upload_temp.sql, packages/database/supabase/schemas/embedding.sql, packages/database/supabase/schemas/sync.sql
Removes the entire upload_temp.sql file, which defined several upsert and sync functions. Deletes the full definition and ownership of match_content_embeddings from embedding.sql and adds a drop statement. Removes the get_nodes_needing_sync function and related grants from sync.sql, replacing them with a drop statement.
Configuration update
packages/database/supabase/config.toml
Removes the now-deleted ./schemas/upload_temp.sql from the [db.migrations] schema file list in the configuration.
Generated TypeScript types
packages/database/types.gen.ts
Deletes TypeScript type declarations for all removed functions from the generated database types, and adjusts the property order in one unrelated function's return type.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Database

    Note over Client,Database: (Old flow - now removed)
    Client->>Database: Call upsert_discourse_nodes / alpha_upsert_discourse_nodes
    Database-->>Client: Upsert nodes, return results

    Client->>Database: Call get_nodes_needing_sync
    Database-->>Client: Return nodes needing sync

    Client->>Database: Call match_content_embeddings
    Database-->>Client: Return similar content

    Note over Client,Database: (All above functions are now removed)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


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.

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: 0

🧹 Nitpick comments (1)
packages/database/supabase/schemas/sync.sql (1)

222-222: Schema file now drops get_nodes_needing_sync – keep schema & migrations in sync.

Good to see the schema reflecting the drop. Just make sure the corresponding migration (20250803100134_drop-get_nodes_needing_sync.sql) is always applied after this schema file during fresh-schema bootstrap so a CREATE …; DROP …; ordering conflict cannot occur for new environments.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 71ae29f and 47e71f0.

📒 Files selected for processing (7)
  • packages/database/supabase/config.toml (0 hunks)
  • packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql (1 hunks)
  • packages/database/supabase/migrations/20250803100134_drop-get_nodes_needing_sync.sql (1 hunks)
  • packages/database/supabase/schemas/embedding.sql (1 hunks)
  • packages/database/supabase/schemas/sync.sql (1 hunks)
  • packages/database/supabase/schemas/upload_temp.sql (0 hunks)
  • packages/database/types.gen.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/database/supabase/config.toml
  • packages/database/supabase/schemas/upload_temp.sql
🧰 Additional context used
🧠 Learnings (22)
📓 Common learnings
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#189
File: packages/database/supabase/migrations/20250603144146_account_centric.sql:50-63
Timestamp: 2025-06-04T11:41:34.951Z
Learning: In the discourse-graph database, all accounts currently stored are Roam platform accounts, making platform-specific migration logic safe for global operations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-13T16:47:14.352Z
Learning: In the discourse-graph codebase, database functions that use STRICT clauses and ON CONFLICT statements already have appropriate error handling. Suggesting additional explicit error handling may be unnecessary and could introduce performance overhead through extra database queries.
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#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/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/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#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#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#291
File: packages/database/supabase/functions/create-space/index.ts:0-0
Timestamp: 2025-07-21T14:22:20.752Z
Learning: In the discourse-graph codebase, types.gen.ts is not accessible from Supabase edge functions, requiring duplication of types and utilities when needed in the edge function environment at packages/database/supabase/functions/.
📚 Learning: migration files in packages/database/supabase/migrations/ are historical snapshots that preserve dat...
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.

Applied to files:

  • packages/database/supabase/migrations/20250803100134_drop-get_nodes_needing_sync.sql
  • packages/database/supabase/schemas/sync.sql
  • packages/database/supabase/schemas/embedding.sql
  • packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql
📚 Learning: for the discourse-graph project, database schema management focuses on the final state in the supaba...
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.

Applied to files:

  • packages/database/supabase/migrations/20250803100134_drop-get_nodes_needing_sync.sql
  • packages/database/supabase/schemas/sync.sql
  • packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql
📚 Learning: database migration files (like the sql files in packages/database/supabase/migrations/) should not b...
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.

Applied to files:

  • packages/database/supabase/migrations/20250803100134_drop-get_nodes_needing_sync.sql
  • packages/database/supabase/schemas/sync.sql
  • packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql
📚 Learning: supabase automatically creates necessary schemas like the "extensions" schema before migrations run,...
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.

Applied to files:

  • packages/database/supabase/migrations/20250803100134_drop-get_nodes_needing_sync.sql
  • packages/database/supabase/schemas/sync.sql
  • packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql
📚 Learning: the necessary schemas for supabase extensions (like 'extensions', 'graphql', and 'vault') are automa...
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.

Applied to files:

  • packages/database/supabase/migrations/20250803100134_drop-get_nodes_needing_sync.sql
  • packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql
📚 Learning: in the `match_embeddings_for_subset_nodes` sql function in packages/database/supabase/schemas/embedd...
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/schemas/embedding.sql:66-95
Timestamp: 2025-05-20T14:04:19.632Z
Learning: In the `match_embeddings_for_subset_nodes` SQL function in packages/database/supabase/schemas/embedding.sql, the number of results is implicitly limited by the length of the input array parameter `p_subset_roam_uids` since the function filters content using `WHERE c.source_local_id = ANY(p_subset_roam_uids)`.

Applied to files:

  • packages/database/supabase/schemas/sync.sql
  • packages/database/supabase/schemas/embedding.sql
  • packages/database/types.gen.ts
📚 Learning: when reviewing sql migrations in this codebase, understand that historical migration files should no...
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."

Applied to files:

  • packages/database/supabase/schemas/sync.sql
  • packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql
📚 Learning: in apps/website/app/utils/supabase/dbutils.ts, expanding the known_embeddings and default_dimensions...
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.

Applied to files:

  • packages/database/supabase/schemas/embedding.sql
  • packages/database/types.gen.ts
  • packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql
📚 Learning: when reviewing sql functions in the discourse-graph codebase, be mindful that suggesting additional ...
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.

Applied to files:

  • packages/database/supabase/schemas/embedding.sql
  • packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql
📚 Learning: the search-content route (apps/website/app/api/supabase/rpc/search-content/route.ts) is intentionall...
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/api/supabase/rpc/search-content/route.ts:53-56
Timestamp: 2025-05-30T14:37:30.215Z
Learning: The search-content route (apps/website/app/api/supabase/rpc/search-content/route.ts) is intentionally designed to be platform-agnostic rather than Roam-specific. The generic "Platform" terminology (like subsetPlatformIds) is used because the route will support multiple platforms in the near future, not just Roam.

Applied to files:

  • packages/database/supabase/schemas/embedding.sql
  • packages/database/types.gen.ts
📚 Learning: in the discourse-graph codebase, types.gen.ts contains automatically generated database function typ...
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.

Applied to files:

  • packages/database/types.gen.ts
📚 Learning: in the discourse-graph codebase, types.gen.ts is not accessible from supabase edge functions, requir...
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#291
File: packages/database/supabase/functions/create-space/index.ts:0-0
Timestamp: 2025-07-21T14:22:20.752Z
Learning: In the discourse-graph codebase, types.gen.ts is not accessible from Supabase edge functions, requiring duplication of types and utilities when needed in the edge function environment at packages/database/supabase/functions/.

Applied to files:

  • packages/database/types.gen.ts
📚 Learning: applies to **/*.{ts,tsx} : use explicit return types for functions...
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-07-19T22:34:08.725Z
Learning: Applies to **/*.{ts,tsx} : Use explicit return types for functions

Applied to files:

  • packages/database/types.gen.ts
📚 Learning: the team prefers not to manually edit generated files (like supabase typescript types) even when the...
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/types.gen.ts:336-371
Timestamp: 2025-06-04T11:54:37.239Z
Learning: The team prefers not to manually edit generated files (like Supabase TypeScript types) even when they contain inaccuracies, as manual changes would be overwritten during regeneration. They treat generated files as read-only artifacts.

Applied to files:

  • packages/database/types.gen.ts
📚 Learning: the packages/database directory in the discourse-graph repository has a unique structure as a databa...
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.

Applied to files:

  • packages/database/types.gen.ts
  • packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql
📚 Learning: currently, there are no obsidian spaces in the database - all existing spaces are roam spaces. this ...
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/supabase/migrations/20250603144146_account_centric.sql:123-136
Timestamp: 2025-06-04T11:41:08.589Z
Learning: Currently, there are no Obsidian spaces in the database - all existing spaces are Roam spaces. This means database migrations targeting space platform assignments only need to handle Roam for now.

Applied to files:

  • packages/database/types.gen.ts
📚 Learning: applies to apps/roam/**/*.{js,jsx,ts,tsx} : use the roamalphaapi documentation from https://roamrese...
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-07-19T22:34:23.619Z
Learning: Applies to apps/roam/**/*.{js,jsx,ts,tsx} : Use the roamAlphaApi documentation from https://roamresearch.com/#/app/developer-documentation/page/tIaOPdXCj when working with the Roam API

Applied to files:

  • packages/database/types.gen.ts
📚 Learning: in apps/roam/src/utils/getalldiscoursenodessince.ts, the user confirmed that querying for `?title` w...
Learnt from: sid597
PR: DiscourseGraphs/discourse-graph#232
File: apps/roam/src/utils/getAllDiscourseNodesSince.ts:18-31
Timestamp: 2025-06-22T10:40:52.752Z
Learning: In apps/roam/src/utils/getAllDiscourseNodesSince.ts, the user confirmed that querying for `?title` with `:node/title` and mapping it to the `text` field in the DiscourseGraphContent type is the correct implementation for retrieving discourse node content from Roam Research, despite it appearing to query page titles rather than block text content.

Applied to files:

  • packages/database/types.gen.ts
📚 Learning: in the discourse-graph project's upsert_content function, null creator_id values are tolerated as an...
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.

Applied to files:

  • packages/database/types.gen.ts
📚 Learning: in the discoursenode interface from apps/roam/src/utils/getdiscoursenodes.ts, the field `type` serve...
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#220
File: apps/roam/src/utils/conceptConversion.ts:42-56
Timestamp: 2025-06-17T23:37:45.289Z
Learning: In the DiscourseNode interface from apps/roam/src/utils/getDiscourseNodes.ts, the field `type` serves as the unique identifier field, not a type classification field. The interface has no `uid` or `id` field, making `node.type` the correct field to use for UID-related operations.

Applied to files:

  • packages/database/types.gen.ts
📚 Learning: in the discoursenode interface from apps/roam/src/utils/getdiscoursenodes.ts, the field `node.type` ...
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#220
File: apps/roam/src/utils/conceptConversion.ts:42-56
Timestamp: 2025-06-17T23:37:45.289Z
Learning: In the DiscourseNode interface from apps/roam/src/utils/getDiscourseNodes.ts, the field `node.type` serves as the UID field rather than having a conventional `node.uid` field. This is an unusual naming convention where the type field actually contains the unique identifier.

Applied to files:

  • packages/database/types.gen.ts
⏰ 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 (4)
packages/database/supabase/schemas/embedding.sql (1)

75-77: Update migrations before dropping match_content_embeddings

The function is still being re-created by two existing migrations, so simply dropping it in the schema will not fully remove it and may lead to unexpected behavior when replaying or reverting migrations.

• packages/database/supabase/migrations/20250513173724_content_concept_key.sql:43 – CREATE OR REPLACE FUNCTION public.match_content_embeddings(...)
• packages/database/supabase/migrations/20250520132747_restrict_search_by_document.sql:1 – CREATE OR REPLACE FUNCTION public.match_content_embeddings(...)

Please remove or adjust these migration definitions (or consolidate them) to fully deprecate the function before running the DROP in your schema.

⛔ Skipped due to learnings
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#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#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#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#165
File: packages/database/supabase/schemas/embedding.sql:66-95
Timestamp: 2025-05-20T14:04:19.632Z
Learning: In the `match_embeddings_for_subset_nodes` SQL function in packages/database/supabase/schemas/embedding.sql, the number of results is implicitly limited by the length of the input array parameter `p_subset_roam_uids` since the function filters content using `WHERE c.source_local_id = ANY(p_subset_roam_uids)`.
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/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#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.
packages/database/supabase/migrations/20250803100134_drop-get_nodes_needing_sync.sql (1)

1-2: No lingering callers of get_nodes_needing_sync found
All references to this function are confined to SQL migration and schema files. A repo-wide search excluding .sql files returned zero hits in TypeScript RPC wrappers, cron jobs, or Supabase edge functions:

  • packages/database/supabase/migrations/20250520133551_nodes_needing_sync.sql
  • packages/database/supabase/schemas/sync.sql

It’s safe to drop this function in the new migration.

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

637-641: Generated file – field order change only. No action required.

packages/database/supabase/migrations/20250803092544_drop-unused-functions.sql (1)

1-10: No references to dropped functions remain
A full‐repo search for both function calls and string literals confirmed that none of the following are used outside of the drop migration:

  • alpha_delete_by_source_local_ids
  • alpha_get_last_update_time
  • alpha_upsert_discourse_nodes
  • match_content_embeddings
  • upsert_discourse_nodes

Safe to merge.

@sid597 sid597 requested review from maparent and mdroidian August 3, 2025 10:16

set search_path to public, extensions ;

CREATE OR REPLACE FUNCTION public.match_content_embeddings (
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know if this function should be removed.
On the one hand you are correct that it is not currently used. OTOH It allows functionality that is not there otherwise, and could be used.
That said... Search architecture will be rethought soon, so it's not like we're going to get to use it in this exact shape.
I guess I'm a -0 on this. Not going to fight it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I mis-remembered and thought I created both these functions and now the other one is being used, I don't have any opinions on which one to keep. Since you see a use for this in future I will keep this one and remove the other one

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would not remove the other one! It fits a real and distinct use case.
I originally had a single function which handled both use cases, but @mdroidian thought it was confusing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok no embedding function is being removed now.

Copy link
Collaborator

@maparent maparent left a comment

Choose a reason for hiding this comment

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

The drop in schema is the only one I'd block on, but the upper-case should not be hard.
Otherwise I'm good with this.

@sid597 sid597 requested a review from maparent August 7, 2025 10:47
Copy link
Collaborator

@maparent maparent left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@maparent
Copy link
Collaborator

maparent commented Aug 8, 2025

The failure is due to merging the migrations. Trying to solve this.

@maparent
Copy link
Collaborator

maparent commented Aug 8, 2025

For some reason I get errors with supabase when trying to do a supabase link. Something is really off with supabase. So without the link, I deleted the migrations by hand in the supabase sql interface. (We need a better flow for this, but it would involve supabase link.)
AND that should have solved the problem, but I also cannot re-run the failed step to check that. (Or rather I can ask, but the step is not re-run.)
What I suggest: Re-do a push, (maybe whitespace) and we'll see if that fixes the validation issue since I've deleted the migrations.

@maparent
Copy link
Collaborator

maparent commented Aug 8, 2025

(Or we could ignore the failing check, but that's probably bad practice.)

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.

Supabase build failing. As @maparent suggested, try re-pushing to trigger it again.

@sid597
Copy link
Collaborator Author

sid597 commented Aug 10, 2025

@maparent @mdroidian build is passing now

@mdroidian mdroidian merged commit a8b3c8f into main Aug 10, 2025
4 checks passed
@mdroidian mdroidian deleted the eng-450-remove-unused-db-functions branch August 10, 2025 20:28
@github-project-automation github-project-automation bot moved this to Done in General Aug 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants