Skip to content

feat: hierarchical documents — tree engine with depth-10 support #438

Closed

Description

@ajianaz

Summary

Add parent-child hierarchy to the document engine, supporting trees up to depth 10. Uses hybrid adjacency list + materialized path for O(1) subtree queries.

Schema Changes (v11 → v12)

  • parent_id TEXT REFERENCES documents(id) ON DELETE CASCADE — adjacency
  • path TEXT NOT NULL DEFAULT "" — materialized path (UUID-based, e.g. /a1b2/c3d4/)
  • depth INTEGER NOT NULL DEFAULT 0 — denormalized depth
  • sort_order INTEGER NOT NULL DEFAULT 0 — manual ordering within parent
  • has_children INTEGER NOT NULL DEFAULT 0 — denormalized flag

CLI Commands

  • uteke doc create --parent <slug> — create child document
  • uteke doc list --tree [--max-depth N] — tree view with indentation
  • uteke doc move <slug> --parent <new-parent> — re-parent subtree
  • uteke doc breadcrumbs <slug> — path from root to node
  • uteke doc descendants <slug> [--max-depth N] — list subtree

Store Methods

  • Insert document with parent resolution + path generation
  • Subtree query via path prefix scan (LIKE "/prefix/%")
  • Breadcrumb query via path UUID extraction
  • Move subtree (path string replace + depth recalc)
  • Cascade delete safety (subtree size check)

Safety Guards

  • Circular reference prevention (parent_id != self, parent depth < own depth)
  • --force required to delete non-empty parents
  • Subtree size warning before delete

Effort

~24-32 hours (3-4 days) across schema, store, lib, CLI, server API, and tests.

Related

Activity

  1. added
    enhancement
    on Jun 22, 2026
  2. ajianaz commented on Jun 22, 2026

    @ajianaz
    CollaboratorAuthor

    Closed: implemented in PR #439 (merged) + PR #441 (API endpoints). Hierarchical docs, tree ops, hybrid search all shipped on develop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions