Repository navigation
Description
Overview
Extend SchemaService to support creating user-defined schemas with automatic database schema generation. When a user-defined schema is created, the system atomically creates spoke tables, relation tables, schema nodes, and hub nodes.
Self-Contained Scope
- Extend SchemaService with
create_user_schema()method - Auto-generate relation names for reference fields (
{source_type}_{field_name}) - Atomic transaction creates: spoke table (SCHEMALESS), relation tables, schema node, hub node
- Support nested/composite fields as JSON objects (stored in spoke table)
- Validate schema definitions before creation (check reference types exist)
- Expose via MCP handler for programmatic access
Implementation Approach
- Extend SchemaService with user schema creation method
- Implement auto-relation naming convention for reference fields
- Build atomic transaction generator for schema + DDL statements
- Add nested field support (JSON object storage in spoke)
- Implement schema validation (referenced types must exist)
- Update MCP handler to expose new schema methods
- Test with example: Invoice tracking system
Acceptance Criteria
-
SchemaService::create_user_schema()creates spoke table, relations, and schema nodes atomically - Relation names auto-generated consistently (
invoice_customer,task_assignee) - Field types automatically determine storage strategy (field vs relation)
- Atomic transaction ensures all-or-nothing creation
- Nested fields stored as JSON objects with metadata in schema node
- Schema validation prevents invalid type references
- MCP handler exposes create/update/delete schema methods
- Tests verify complete schema creation flow
- Documentation explains schema creation process
Current Status
Test Results:
- Frontend tests (Bun): 1644 passing ✅
- Rust schema/task tests: Failing due to spoke table persistence issue
Latest Work:
- Fixed schema.surql ASSERT constraints that were blocking spoke creation
- Identified spoke table persistence/retrieval issue affecting all spoke-based types
Blocker:
The hub-and-spoke architecture is not correctly persisting/retrieving properties from spoke tables. When CREATE is executed for spoke records, it returns success, but subsequent SELECT queries find no records. This affects:
- Task nodes (status, priority, etc.)
- Schema nodes (is_core, version, fields)
- Any future node type with properties
The root cause appears to be in how the spoke CREATE query is executing or how properties are being serialized.
Technical Implementation Notes
Hub-and-Spoke Architecture Status
Implemented:
- Universal hub table with metadata
- Spoke tables defined in schema.surql
- CREATE/UPDATE/SELECT logic in surreal_store.rs
- get_node() method with OMIT pattern for property retrieval
Issue:
Spoke records not persisting despite successful CREATE responses. Need to:
- Verify CREATE actually inserts into database
- Check SELECT query format and table references
- Debug serde_json serialization of properties
- Validate SurrealDB embedded database persistence
Files Modified
packages/core/src/db/schema.surql:
- Changed task/schema/date spoke id/node fields from required to optional<record>
- Removed ASSERT constraints preventing spoke creation
packages/core/src/db/surreal_store.rs:
- Simplified spoke CREATE query
- Added proper response consumption
packages/core/src/services/schema_service.rs:
- Implements create_user_schema() with DDL generation
- Creates schema nodes with properties
- Creates spoke tables for type-specific data
Next Steps
- Debug spoke table CREATE/SELECT behavior
- Fix task node persistence (blocker for all spoke-based types)
- Verify schema node properties are persisted
- Run full test suite and fix regressions
- Complete remaining acceptance criteria
Activity
[-]Implement LLM-driven user-defined schema creation with automatic database generation[/-][+]Extend SchemaService to support user-defined schema creation with automatic database generation[/+]Add LIVE SELECT architecture documentation and align data schema specs
Extend SchemaService to support user-defined schema creation with aut…
malibio commentedon Nov 20, 2025
Scope Clarification: Create vs Update/Delete
Based on code review feedback, I'm clarifying the scope of this PR:
This PR (Issue #562): Implements CREATE user schema functionality
Future PRs: Update and delete functionality
Recommendation: Create follow-up issues for update/delete with proper acceptance criteria and design discussion.
This follows the vertical slicing principle: complete one feature fully before adding related features.
Address code review: Fix SQL injection and improve atomicity
WIP: Investigation of 30 failing schema tests - root cause identified
malibio commentedon Nov 21, 2025
Architecture Corrections and Response Consumption Fix - Session Complete
What Was Fixed
✅ Response Consumption Bug: UPDATE query on line 893 now properly consumes response with
.take(0)✅ Schema Architecture Alignment: Removed non-existent
propertiesfield from hub node schema✅ Hub-Spoke Pattern: Properties now stored ONLY in spoke tables, hub keeps clean separation
Key Discoveries
propertiesfield that doesn't exist in schema.surqldocs/architecture/development/hierarchy-reactivity-architecture-review.mdRemaining Work for Next Agent
Priority 1: Decide on schema storage approach (3 options documented in commit message)
fieldsarray fieldPriority 2: Fix test_schema_operations once storage pattern is decided
Priority 3: Validate if other 90 failing tests have same root cause
Test Status
Code Changes
Next Agent: See detailed handoff in commit
1a768c4- includes recommended approach and migration path.WIP: Fix SurrealDB query syntax and schema table definition - spoke r…
Docs: Add SurrealDB troubleshooting guide and fix schema definitions
Fix: Schema fields hydration - stringify complex fields array for Sur…
WIP: Schema field serialization fixed - ready for create_user_schema …
10 remaining items
Document SurrealDB deserialization patterns and add expert guidance (…
Fix schema serialization - use strong typing for enum deserialization…
WIP: Investigate spoke record persistence issue - SCHEMALESS conversi…
WIP: Investigate spoke record persistence - 52 tests blocked (Issue #562
Fix spoke record persistence: Use OMIT for Thing types in SELECT queries
Implement SurrealDB graph traversal syntax for mention system (Issue #…
Add LIVE SELECT architecture documentation and align data schema specs
Extend SchemaService to support user-defined schema creation with aut…
--title (#606)
Add LIVE SELECT architecture documentation and align data schema specs
Extend SchemaService to support user-defined schema creation with aut…
--title (#606)
Extend SchemaService to support user-defined schema creation with aut…
--title (#606)