Repository navigation
Closed
Labels
Description
Overview
Consolidate the separate edge tables (has_child, mentions, member_of) into a single universal edge table with type discrimination. This follows the same pattern as Universal Nodes and enables custom relationship types without DDL.
Architecture Context
This issue is part of Epic #783 (Universal Graph Architecture Transition), Stream B: Data Model Transition.
The Universal Edge Table follows the same principle as Universal Nodes:
- Single table with
edge_typediscriminator - Type-specific data in
propertiesJSON field - Partial indexes for performance
- Zero DDL for custom relationship types
See: docs/architecture/architecture-target-state.md Section 2
Current State
Three separate edge tables:
-- has_child: Document tree hierarchy
DEFINE TABLE has_child TYPE RELATION IN node OUT node;
DEFINE FIELD order ON has_child TYPE float;
-- mentions: @references and [[links]]
DEFINE TABLE mentions TYPE RELATION IN node OUT node;
DEFINE FIELD context ON mentions TYPE string;
DEFINE FIELD offset ON mentions TYPE int;
DEFINE FIELD root_id ON mentions TYPE option<string>;
-- member_of: Collection membership
DEFINE TABLE member_of TYPE RELATION IN node OUT node;Target State
Single universal edge table:
DEFINE TABLE edge SCHEMAFULL TYPE RELATION IN node OUT node;
DEFINE FIELD edge_type ON TABLE edge TYPE string ASSERT $value != NONE;
DEFINE FIELD properties ON TABLE edge TYPE object DEFAULT {};
DEFINE FIELD version ON TABLE edge TYPE int DEFAULT 1;
DEFINE FIELD created_at ON TABLE edge TYPE datetime DEFAULT time::now();
DEFINE FIELD modified_at ON TABLE edge TYPE datetime DEFAULT time::now();
-- Core indexes
DEFINE INDEX idx_edge_type ON TABLE edge COLUMNS edge_type;
DEFINE INDEX idx_edge_in ON TABLE edge COLUMNS in, edge_type;
DEFINE INDEX idx_edge_out ON TABLE edge COLUMNS out, edge_type;
-- Partial indexes for core types
DEFINE INDEX idx_edge_child_order ON edge
COLUMNS in, properties.order
WHERE edge_type = 'has_child';
DEFINE INDEX idx_edge_unique_child ON edge
COLUMNS in, out UNIQUE
WHERE edge_type = 'has_child';
DEFINE INDEX idx_edge_mentions_target ON edge
COLUMNS out
WHERE edge_type = 'mentions';Why Universal Edge Table
| Aspect | Separate Tables | Single Edge Table |
|---|---|---|
| Custom relationships | Requires DDL | Zero DDL |
| Playbook Marketplace | Can't add relationship types | Install adds new edge_types |
| Consistency | Nodes unified, edges fragmented | Fully unified model |
| Query all relationships | UNION across tables | Single table query |
| Sync complexity | Multiple edge tables | One edge table |
Acceptance Criteria
Phase 1: Schema & Migration
- Create
edgetable with universal schema - Migrate
has_childdata →edgewithedge_type: 'has_child' - Migrate
mentionsdata →edgewithedge_type: 'mentions' - Migrate
member_ofdata →edgewithedge_type: 'member_of' - Add partial indexes for core edge types
- Remove old edge tables
Phase 2: Rust Code Updates
- Update edge creation functions to use universal table
- Update edge query functions (get_children, get_mentions, etc.)
- Update graph traversal code
- Remove old table-specific code
Phase 3: Frontend Updates
- Update any direct edge table references
- Verify hierarchy operations work (indent, outdent, reorder)
- Verify mention/backlink features work
Phase 4: Quality
- All existing tests pass
- New tests for edge_type filtering
- Code passes
bun run quality:fix - Tests pass (
bun run test:all)
Technical Specifications
Edge Properties by Type
has_child:
{ "properties": { "order": 1.5 } }mentions:
{ "properties": { "context": "See also", "offset": 42, "root_id": "node:abc123" } }member_of:
{ "properties": {} }Query Changes
Before:
SELECT out.* FROM has_child WHERE in = $parent_id ORDER BY order ASC;After:
SELECT out.* FROM edge
WHERE in = $parent_id AND edge_type = 'has_child'
ORDER BY properties.order ASC;Files to Modify
- Schema:
packages/desktop-app/src-tauri/src/db/schema.surql - Edge operations:
packages/desktop-app/src-tauri/src/services/ - Hierarchy service: Parent/child operations
- Mention service: Reference tracking
- Collection service: Membership operations
Dependencies
- Should be done alongside or after node spoke elimination (same Stream B work)
- No external dependencies
Related Issues
- Epic Epic: Universal Graph Architecture Transition #783 - Universal Graph Architecture Transition (parent)
- Node spoke elimination (same stream)
Activity
docs: Add Universal Edge Table to target architecture (#788)
malibio commentedon Jan 6, 2026
Starting work on this issue. Test baseline: Frontend: 101 test files, 3431 tests passed. Rust: 25 tests passed (23 unit + 2 schema parity).
feat(db): Implement Universal Relationship Architecture (Issue #788)
Consolidate Edge Tables into Universal Edge Table (#793)
docs: Update architecture for compound indexes and relationship table
docs: Add Universal Edge Table to target architecture (#788)
Consolidate Edge Tables into Universal Edge Table (#793)
docs: Update architecture for compound indexes and relationship table
docs: Add Universal Edge Table to target architecture (#788)
Consolidate Edge Tables into Universal Edge Table (#793)
docs: Update architecture for compound indexes and relationship table
Consolidate Edge Tables into Universal Edge Table (#793)