feat(filesys): data models and migration#7402
Merged
Conversation
Contributor
Greptile SummaryThis PR introduces the foundational data models and database migration for a hierarchical file system implementation. It adds two new tables ( Key changes:
The implementation is lightweight and focused on hierarchy structure only, keeping permissions and sync logic on the Document model. The migration includes both upgrade and downgrade paths with proper index cleanup. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Migration as Alembic Migration
participant DB as PostgreSQL Database
participant HierarchyNode as hierarchy_node table
participant Document as document table
participant HierarchyFetch as hierarchy_fetch_attempt table
Note over Migration,DB: Migration Upgrade Process
Migration->>DB: Create hierarchy_node table
DB-->>Migration: Table created with columns:<br/>id, raw_node_id, display_name,<br/>link, source, node_type,<br/>document_id, parent_id
Migration->>DB: Add indexes on hierarchy_node
DB-->>Migration: Created ix_hierarchy_node_parent_id<br/>Created ix_hierarchy_node_source_type<br/>Created uq_hierarchy_node_raw_id_source
Migration->>DB: Create hierarchy_fetch_attempt table
DB-->>Migration: Table created with columns:<br/>id, connector_credential_pair_id,<br/>status, nodes_fetched, nodes_updated,<br/>timestamps
Migration->>DB: Add indexes on hierarchy_fetch_attempt
DB-->>Migration: Created ix_hierarchy_fetch_attempt_status<br/>Created ix_hierarchy_fetch_attempt_time_created<br/>Created ix_hierarchy_fetch_attempt_cc_pair
loop For each DocumentSource
Migration->>HierarchyNode: Insert SOURCE-type node
Note right of HierarchyNode: raw_node_id = source value<br/>display_name from lookup dict<br/>node_type = 'source'<br/>parent_id = NULL
end
Migration->>Document: Add parent_hierarchy_node_id column
Document-->>Migration: Column added (nullable)
Migration->>DB: Create foreign key constraint
DB-->>Migration: fk_document_parent_hierarchy_node created
Migration->>DB: Create index on document.parent_hierarchy_node_id
DB-->>Migration: ix_document_parent_hierarchy_node_id created
Migration->>DB: Execute UPDATE query to backfill documents
Note over DB: Query joins document_by_connector_credential_pair<br/>with connector to get source,<br/>then joins hierarchy_node to set parent
DB-->>Migration: All existing documents linked to SOURCE nodes
Note over Migration,DB: Migration Complete - Ready for hierarchy data
|
Contributor
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="backend/alembic/versions/81c22b1e2e78_hierarchy_nodes_v1.py">
<violation number="1" location="backend/alembic/versions/81c22b1e2e78_hierarchy_nodes_v1.py:231">
P2: The index `ix_persona__hierarchy_node_persona_id` is redundant. The composite primary key `(persona_id, hierarchy_node_id)` already creates an index that efficiently supports lookups by `persona_id` alone. This extra index wastes disk space and adds write overhead. Consider removing this index (keep only the `hierarchy_node_id` index, which is necessary).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
a8d7850 to
b6d0627
Compare
a8a8894 to
290e9e3
Compare
acaprau
approved these changes
Jan 27, 2026
b7df988 to
86473fb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Addresses https://linear.app/onyx-app/issue/ENG-3415/migrations-and-data-models
data models and migration for our initial filesys implementation
How Has This Been Tested?
tested that upgrade and downgrade work
Additional Options
Summary by cubic
Adds hierarchy data models and a migration to represent source folder/space trees, link documents to their parent nodes, and let personas attach to hierarchy nodes and individual documents for scoped search. Addresses Linear ENG-3415; also tracks hierarchy fetch attempts and stores the last fetch time on connector credential pairs.
New Features
Migration
Written for commit 9929509. Summary will update on new commits.