Repository navigation
Closed
Description
Overview
Consolidate database schema seeding to use the backend service layer, eliminating hardcoded constants and ensuring spoke table DDL is derived from schema definitions rather than static configuration.
Self-Contained Scope
- Move core schema definitions to Rust using existing
SchemaNodestruct - Create
seed_core_schemas()method for idempotent seeding - Remove
TYPES_WITH_SPOKE_TABLEShardcoded constant - derive spoke table needs from schema definitions - Update database initialization to call the seed method
- Remove redundant seeding from
schema.surqland TypeScript scripts - Comprehensive testing of schema initialization
Key Architectural Decisions
Core Node Types (8 total)
task- has schema entry + spoke table (has fields)text- has schema entry, no spoke table (no fields)date- has schema entry, no spoke table (no fields)header- has schema entry, no spoke table (no fields)code-block- has schema entry, no spoke table (no fields)quote-block- has schema entry, no spoke table (no fields)ordered-list- has schema entry, no spoke table (no fields)schema- NO schema entry (meta-type, handled specially by system)
Schema Nodes Stored in Database (7 total)
- task, text, date, header, code-block, quote-block, ordered-list
- The
schematype is structural - it defines other types but doesn't have a schema definition for itself (would be circular)
Spoke Table Logic
- A node type needs a spoke table if its schema has
fields.len() > 0 - Currently hardcoded in
TYPES_WITH_SPOKE_TABLES = ["task", "schema"] - Should be derived dynamically: query schema node, check if fields exist
- The
schemaspoke table is structural (stores schema definitions), not derived from a schema node
Implementation Approach
Phase 1: Core Schema Definitions
- Create
get_core_schemas()function returningVec<SchemaNode> - Use existing
SchemaNodestruct (no new types needed) - 7 schema definitions for the 7 node types that need schema entries
Phase 2: Dynamic Spoke Table Detection
- Add method to check if a node type needs a spoke table by querying its schema
- Cache schema info after initialization to avoid repeated queries
- Handle special case:
schematype always has spoke table (structural) - Remove
TYPES_WITH_SPOKE_TABLESconstant entirely
Phase 3: Seed Method with DDL Sync
seed_core_schemas()creates schema nodes viaSchemaNode.into_node()- For schemas with fields (task), call
SchemaTableManager.sync_schema_to_database() - Idempotent: check if schemas exist before creating
Phase 4: Remove Redundant Sources
- Remove task spoke table DDL from
schema.surql(generated from schema definition) - Keep
schemaspoke table DDL inschema.surql(structural, not schema-derived) - Delete
init-schemas-via-proxy.ts - Update
package.jsonto removedev:browser:initscript
Acceptance Criteria
- Core schema definitions use existing
SchemaNodestruct -
seed_core_schemas()method creates 7 schema nodes -
seed_core_schemas()syncs spoke table DDL for schemas with fields -
TYPES_WITH_SPOKE_TABLESconstant removed - Spoke table needs derived from schema definitions at runtime
- Task spoke table DDL removed from
schema.surql -
init-schemas-via-proxy.tsdeleted - Database initializes correctly with all core schemas
- All tests pass (
bun run test:all) - Quality checks pass (
bun run quality:fix)
Technical Implementation Notes
Files to modify:
packages/core/src/db/surreal_store.rs- removeTYPES_WITH_SPOKE_TABLES, add dynamic lookuppackages/core/src/db/schema.surql- remove task spoke table definitionspackages/desktop-app/package.json- removedev:browser:initscript
Files to delete:
packages/desktop-app/scripts/init-schemas-via-proxy.ts
Files to create:
packages/core/src/models/core_schemas.rs-get_core_schemas()function
Migration Strategy
The TYPES_WITH_SPOKE_TABLES constant is used in 13 places in surreal_store.rs. Each usage needs to be replaced with a dynamic check:
- Option A: Query-based - Query schema node, check
fields.len() > 0 - Option B: Cached - Build cache at startup after seeding, use for all operations
Option B preferred for performance (avoid repeated queries during CRUD operations).
Dependencies
- Simplify Schema Architecture: Remove SchemaDefinition and SchemaService #690 (merged) - SchemaTableManager available for DDL generation
Definition of Done
- Single source of truth for core schema definitions
- No hardcoded type lists - all derived from schema data
- Database initialization works end-to-end
- All tests pass
- Code review completed
Activity
malibio commentedon Dec 1, 2025
Test baseline (post #690 merge): Frontend: 1440 passed, Rust: 477 passed (16 ignored)
Consolidate database schema seeding to backend service (Issue #691)
Consolidate schema seeding with dynamic spoke table management (Issue #…
malibio commentedon Dec 1, 2025
✅ Implementation complete. Expanded scope to include:
Created follow-up issue #703 for relational fields architecture design.
Remove hardcoded VALID_NODE_TYPES, derive from schemas (Issue #691)
Consolidate Database Schema Seeding to Backend Service (#701)
Update how-to-add-new-node-type.md to reflect current architecture
Consolidate Database Schema Seeding to Backend Service (#701)
Update how-to-add-new-node-type.md to reflect current architecture
Consolidate Database Schema Seeding to Backend Service (#701)
Update how-to-add-new-node-type.md to reflect current architecture
Consolidate Database Schema Seeding to Backend Service (#701)