Skip to content

Schema and Hub-Spoke Architecture Cleanup with Status Value Unification #670

Closed

Description

@malibio

Overview

Multiple architectural inconsistencies in the schema system are causing bugs and confusion. This issue consolidates cleanup work needed to align the hub-spoke architecture, unify status enum values, fix dropdown rendering, and remove dead code from the LibSQL migration.

Problem Statement

1. Broken Schema-Driven Dropdowns

Converting a text node to a task node fails with:

Error: Operation failed: Invalid update: Required field 'status' is missing from task node

Status and priority dropdowns show no options because of a case mismatch between backend and frontend.

2. Inconsistent Status Enum Values

Three different value sets exist:

  • Schema node (seeded in Rust): OPEN, IN_PROGRESS, DONE
  • Rust TaskStatus enum: pending, in_progress, completed, cancelled
  • SurrealDB task table default: 'todo'

3. Dead Code from LibSQL Migration

When migrating from LibSQL to SurrealDB, the architecture changed from single-table with JSON properties to hub-spoke with separate tables. Remnants remain:

  • properties field on hub node table (unused for spoke types)
  • properties field on Rust Node struct (used as transport layer, misleading docs)
  • date spoke table with timezone/is_holiday fields (never used)
  • TYPES_WITH_PROPERTIES constant (misleading name, actually means "types with spoke tables")

4. Schema Field Case Mismatch

Rust SchemaField struct serializes with snake_case:

  • core_values, user_values, field_type

Frontend TypeScript expects camelCase:

  • coreValues, userValues, type

This causes dropdowns to have no options.

5. Validation Ignores Schema Defaults

When converting node types, validation requires status but doesn't apply the schema's default: "OPEN" value.

Proposed Solution

Comprehensive cleanup in phases:

  1. Fix immediate bugs (dropdown rendering, validation defaults)
  2. Unify status enum values across all layers
  3. Remove dead code and update documentation

Acceptance Criteria

Critical Bug Fixes

  • Schema-driven dropdowns show enum options (status, priority)
  • Converting text→task applies default status value from schema
  • No validation errors when converting to task without explicit status

Status Value Unification

  • All layers use canonical values: open, in_progress, done, cancelled
  • Schema node updated with new values
  • Rust TaskStatus enum updated with new values
  • SurrealDB task table default updated
  • Frontend displays friendly labels: "Open", "In Progress", "Done", "Cancelled"

Architecture Cleanup

  • Remove date spoke table from schema.surql
  • Remove properties field from hub node table in schema.surql
  • Rename TYPES_WITH_PROPERTIES to TYPES_WITH_SPOKE_TABLES
  • Update Rust Node struct documentation (remove "Pure JSON schema" references)

Schema System Improvements

  • Add #[serde(rename_all = "camelCase")] to Rust SchemaField struct
  • Change enum values format from string[] to {value: string, label: string}[]
  • Update frontend to read labels from schema

Quality Gates

  • Code passes bun run quality:fix
  • Tests pass (bun run test:all)
  • Existing test baseline maintained (no new failures)

Technical Specifications

Reference Files

Backend (Rust):

  • Schema Definition: packages/core/src/models/schema.rs - Add #[serde(rename_all = "camelCase")] to SchemaField (line 98)
  • Task Status Enum: packages/core/src/models/task_node.rs (lines 39-48) - Update enum variants
  • Schema Seeding: packages/core/src/db/surreal_store.rs (lines 607-680) - Update task schema core_values
  • Spoke Table Constant: packages/core/src/db/surreal_store.rs (line 99) - Rename constant
  • SurrealDB Schema: packages/core/src/db/schema.surql - Remove date table, remove properties field

Frontend (TypeScript/Svelte):

  • Schema Types: packages/desktop-app/src/lib/types/schema.ts (lines 29-49) - Update SchemaField interface
  • Property Form: packages/desktop-app/src/lib/components/property-forms/schema-property-form.svelte - Update getEnumValues
  • Schema Service: packages/desktop-app/src/lib/services/schema-service.ts - Update enum handling

Backend Validation (Rust):

  • Schema Validation: packages/core/src/services/schema_service.rs (lines 943-952) - Apply defaults for required fields

Implementation Details

1. Fix SchemaField Case Mismatch

// packages/core/src/models/schema.rs
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]  // Add this line
pub struct SchemaField {
    // ... fields
}

2. Unify Status Values

Canonical values (use everywhere):

open, in_progress, done, cancelled

Rust enum update:

pub enum TaskStatus {
    Open,        // "open"
    InProgress,  // "in_progress"
    Done,        // "done"
    Cancelled,   // "cancelled"
}

Schema node update:

"core_values": [
  {"value": "open", "label": "Open"},
  {"value": "in_progress", "label": "In Progress"},
  {"value": "done", "label": "Done"},
  {"value": "cancelled", "label": "Cancelled"}
]

SurrealDB default:

DEFINE FIELD IF NOT EXISTS status ON TABLE task TYPE string DEFAULT 'open';

3. Apply Schema Defaults in Validation

// schema_service.rs - In validate_node_against_schema
if field.required.unwrap_or(false) && field_value.is_none() {
    // If field has a default, apply it instead of returning error
    if let Some(default) = &field.default {
        // Apply default value to node properties
        // (implementation detail: may need to return the applied defaults)
    } else {
        return Err(NodeServiceError::invalid_update(...));
    }
}

4. Remove Dead Code

schema.surql changes:

-- REMOVE these lines:
DEFINE TABLE IF NOT EXISTS date SCHEMALESS;
DEFINE FIELD IF NOT EXISTS node ON TABLE date TYPE option<record>;
DEFINE FIELD IF NOT EXISTS timezone ON TABLE date TYPE string DEFAULT 'UTC';
DEFINE FIELD IF NOT EXISTS is_holiday ON TABLE date TYPE bool DEFAULT false;

-- REMOVE from node table:
DEFINE FIELD IF NOT EXISTS properties ON TABLE node FLEXIBLE TYPE option<object>;

surreal_store.rs changes:

// Rename constant
const TYPES_WITH_SPOKE_TABLES: &[&str] = &["task", "schema"];
// Note: "date" intentionally not included (doesn't need spoke table)

Testing Requirements

  • Update existing TaskNode tests to use new status values
  • Update schema service tests for new enum format
  • Add integration test for text→task conversion
  • Verify dropdown rendering in browser tests

Implementation Approach

Phase 1: Critical Bug Fixes

  • Fix SchemaField case mismatch (add serde rename_all)
  • Update validation to apply schema defaults
  • Verify dropdown options now render

Phase 2: Status Value Unification

  • Update Rust TaskStatus enum values
  • Update schema node seed data
  • Update SurrealDB task table default
  • Update all tests using old values

Phase 3: Schema Label Enhancement

  • Change enum format to {value, label}[]
  • Update frontend to display labels
  • Update schema service to handle new format

Phase 4: Dead Code Removal

  • Remove date spoke table
  • Remove properties field from hub
  • Rename constant
  • Update documentation

Non-Goals

  • Adding new spoke tables for other node types
  • Changing the hub-spoke architecture pattern
  • Adding new status values beyond the four canonical ones

Related Issues

  • None identified

Metadata

Metadata

Assignees

Labels

backendbugfrontendrefactor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions