Repository navigation
Consolidate Database Schema Seeding to Backend Service - #701
Conversation
…691) ## Summary - Create core_schemas.rs with get_core_schemas() returning Vec<SchemaNode> - Remove TYPES_WITH_SPOKE_TABLES hardcoded constant - derive from schema definitions - Add create_schema_node_atomic() for atomic schema creation + DDL sync - Update NodeService.create_node() to handle schema nodes atomically - Fix SchemaTableManager DDL generation (SCHEMAFULL, TABLE keyword, FLEXIBLE, COLUMNS) - Remove task spoke table DDL from schema.surql (now generated dynamically) - Delete init-schemas-via-proxy.ts TypeScript seeding script ## Key Changes **Core Definitions (packages/core/src/models/core_schemas.rs)** - get_core_schemas() returns Vec<SchemaNode> for all 7 core schemas - Uses existing SchemaNode struct (no new types) - Task schema has 6 fields (status, priority, due_date, started_at, completed_at, assignee) - Simple schemas (text, date, header, code-block, quote-block, ordered-list) have no fields **Dynamic Spoke Table Detection (packages/core/src/db/surreal_store.rs)** - Added types_with_spoke_tables: HashSet<String> field to SurrealStore - Added has_spoke_table() method to check if a type needs a spoke table - Added build_spoke_table_cache() to derive spoke table needs from schema definitions - Schema type always has spoke table (structural) - Other types have spoke tables if their schema has fields.len() > 0 - Removed TYPES_WITH_SPOKE_TABLES constant entirely **Atomic Schema Operations (packages/core/src/db/surreal_store.rs)** - Added create_schema_node_atomic() for atomic schema creation + DDL execution - Transaction order: DDL FIRST, then CREATE hub + spoke - Matches update_schema_node_atomic() pattern for consistency **NodeService Integration (packages/core/src/services/node_service.rs)** - Updated create_node() to detect schema nodes and use atomic creation - Generates DDL via SchemaTableManager.generate_ddl_statements() - Ensures schema definition and spoke table are created together **SchemaTableManager Fixes (packages/core/src/services/schema_table_manager.rs)** - Changed to SCHEMAFULL (not SCHEMALESS) for proper field enforcement - Added TABLE keyword: "ON TABLE task" not "ON task" - Added FLEXIBLE to field definitions for user extensions - Changed index syntax: COLUMNS not FIELDS - Added option<> wrapping for optional fields - Added DEFAULT values for required fields with defaults - Added node field (reverse link to hub) for all spoke tables **Schema DDL Cleanup (packages/core/src/db/schema.surql)** - Removed task spoke table definitions (lines 42-59) - Kept schema spoke table (structural, not schema-derived) - Updated header comments to reflect dynamic generation **TypeScript Cleanup** - Deleted packages/desktop-app/scripts/init-schemas-via-proxy.ts (321 lines) - Removed dev:browser:init from package.json - Updated dev:browser to skip init step ## Testing Frontend: 1440 passed (same as baseline) Rust: 482 passed (16 ignored) - same as baseline ## Architecture Notes 8 core node types, 7 with schema entries: 1. task - has schema + spoke table 2-7. text, date, header, code-block, quote-block, ordered-list - schema only, no spoke tables 8. schema - NO schema entry (meta-type, structural spoke table in schema.surql) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
b6fef90 to
082b845
Compare
Code Review: PR #701 - Consolidate Database Schema Seeding to Backend ServiceReview Type: Initial Review Requirements Check (Issue #691)
All acceptance criteria met. Code Review FindingsArchitecture & Design (Critical Priority) - APPROVED🟢 Excellent architectural improvement: The consolidation from hardcoded
📝 File: Functionality & Correctness (Critical Priority) - APPROVED🟢 Guard clause correctly prevents DDL generation for simple schemas: // surreal_store.rs:711
let ddl_statements = if !schema.fields.is_empty() {
table_manager.generate_ddl_statements(&schema_id, &schema.fields)
} else {
vec![]
};This ensures 🟢 Transaction ordering is correct ( Security (Non-Negotiable) - APPROVED🟢 SQL injection prevention maintained:
Maintainability & Readability (High Priority) - APPROVED🟢 Excellent code organization:
🟢 Naming improvements:
Testing Strategy (High Priority) - APPROVED🟢 Test coverage maintained:
🟡 [Nit] Consider adding an integration test that verifies spoke tables are created correctly during database initialization. This would catch any regression in the atomic seeding logic. Performance (Important) - APPROVED🟢 Efficient caching strategy:
Dependencies & Documentation (Important) - APPROVED🟢 Cleanup completed:
Pre-Existing Issue (Not Blocking)ℹ️ Note: There is a pre-existing inconsistency in
SummaryThis is an excellent refactoring that:
The implementation follows established patterns (atomic transactions, hub-spoke architecture), maintains test coverage, and properly handles edge cases. RecommendationAPPROVE ✅ This change is a definitive net positive for code health. All acceptance criteria are met, tests pass, and the architecture is cleaner and more maintainable. |
malibio
left a comment
There was a problem hiding this comment.
Code review completed. Recommendation: APPROVE. All acceptance criteria met - this is a definitive net positive for code health.
Address Review SummaryThe code review was APPROVED with all 10 acceptance criteria met. Recommendations Analysis
Skipped Recommendations🟡 [Nit] Integration Test for Spoke Table Creation Reason: Scope creep / Follow-up item
Final Status
|
Fixes pre-existing inconsistency where VALID_NODE_TYPES used underscores (code_block, quote_block, ordered_list) while actual node types use hyphens (code-block, quote-block, ordered-list). Instead of fixing the typos, removed the redundant hardcoded constant entirely. Valid node types are now derived from schema definitions at runtime, matching the approach used for TYPES_WITH_SPOKE_TABLES. Changes: - Remove VALID_NODE_TYPES constant and standalone validate_node_type fn - Rename build_spoke_table_cache -> build_schema_caches (returns both) - Add valid_node_types field to SurrealStore struct - Add validate_node_type() method to SurrealStore - Update constructors and bootstrap code to initialize both caches Benefits: - Single source of truth: schema definitions drive validation - No risk of underscore/hyphen typos - Automatically supports new schema types without code changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
* Consolidate schema seeding with dynamic spoke table management (Issue #691) ## Summary - Create core_schemas.rs with get_core_schemas() returning Vec<SchemaNode> - Remove TYPES_WITH_SPOKE_TABLES hardcoded constant - derive from schema definitions - Add create_schema_node_atomic() for atomic schema creation + DDL sync - Update NodeService.create_node() to handle schema nodes atomically - Fix SchemaTableManager DDL generation (SCHEMAFULL, TABLE keyword, FLEXIBLE, COLUMNS) - Remove task spoke table DDL from schema.surql (now generated dynamically) - Delete init-schemas-via-proxy.ts TypeScript seeding script ## Key Changes **Core Definitions (packages/core/src/models/core_schemas.rs)** - get_core_schemas() returns Vec<SchemaNode> for all 7 core schemas - Uses existing SchemaNode struct (no new types) - Task schema has 6 fields (status, priority, due_date, started_at, completed_at, assignee) - Simple schemas (text, date, header, code-block, quote-block, ordered-list) have no fields **Dynamic Spoke Table Detection (packages/core/src/db/surreal_store.rs)** - Added types_with_spoke_tables: HashSet<String> field to SurrealStore - Added has_spoke_table() method to check if a type needs a spoke table - Added build_spoke_table_cache() to derive spoke table needs from schema definitions - Schema type always has spoke table (structural) - Other types have spoke tables if their schema has fields.len() > 0 - Removed TYPES_WITH_SPOKE_TABLES constant entirely **Atomic Schema Operations (packages/core/src/db/surreal_store.rs)** - Added create_schema_node_atomic() for atomic schema creation + DDL execution - Transaction order: DDL FIRST, then CREATE hub + spoke - Matches update_schema_node_atomic() pattern for consistency **NodeService Integration (packages/core/src/services/node_service.rs)** - Updated create_node() to detect schema nodes and use atomic creation - Generates DDL via SchemaTableManager.generate_ddl_statements() - Ensures schema definition and spoke table are created together **SchemaTableManager Fixes (packages/core/src/services/schema_table_manager.rs)** - Changed to SCHEMAFULL (not SCHEMALESS) for proper field enforcement - Added TABLE keyword: "ON TABLE task" not "ON task" - Added FLEXIBLE to field definitions for user extensions - Changed index syntax: COLUMNS not FIELDS - Added option<> wrapping for optional fields - Added DEFAULT values for required fields with defaults - Added node field (reverse link to hub) for all spoke tables **Schema DDL Cleanup (packages/core/src/db/schema.surql)** - Removed task spoke table definitions (lines 42-59) - Kept schema spoke table (structural, not schema-derived) - Updated header comments to reflect dynamic generation **TypeScript Cleanup** - Deleted packages/desktop-app/scripts/init-schemas-via-proxy.ts (321 lines) - Removed dev:browser:init from package.json - Updated dev:browser to skip init step ## Testing Frontend: 1440 passed (same as baseline) Rust: 482 passed (16 ignored) - same as baseline ## Architecture Notes 8 core node types, 7 with schema entries: 1. task - has schema + spoke table 2-7. text, date, header, code-block, quote-block, ordered-list - schema only, no spoke tables 8. schema - NO schema entry (meta-type, structural spoke table in schema.surql) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove hardcoded VALID_NODE_TYPES, derive from schemas (Issue #691) Fixes pre-existing inconsistency where VALID_NODE_TYPES used underscores (code_block, quote_block, ordered_list) while actual node types use hyphens (code-block, quote-block, ordered-list). Instead of fixing the typos, removed the redundant hardcoded constant entirely. Valid node types are now derived from schema definitions at runtime, matching the approach used for TYPES_WITH_SPOKE_TABLES. Changes: - Remove VALID_NODE_TYPES constant and standalone validate_node_type fn - Rename build_spoke_table_cache -> build_schema_caches (returns both) - Add valid_node_types field to SurrealStore struct - Add validate_node_type() method to SurrealStore - Update constructors and bootstrap code to initialize both caches Benefits: - Single source of truth: schema definitions drive validation - No risk of underscore/hyphen typos - Automatically supports new schema types without code changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* Consolidate schema seeding with dynamic spoke table management (Issue #691) ## Summary - Create core_schemas.rs with get_core_schemas() returning Vec<SchemaNode> - Remove TYPES_WITH_SPOKE_TABLES hardcoded constant - derive from schema definitions - Add create_schema_node_atomic() for atomic schema creation + DDL sync - Update NodeService.create_node() to handle schema nodes atomically - Fix SchemaTableManager DDL generation (SCHEMAFULL, TABLE keyword, FLEXIBLE, COLUMNS) - Remove task spoke table DDL from schema.surql (now generated dynamically) - Delete init-schemas-via-proxy.ts TypeScript seeding script ## Key Changes **Core Definitions (packages/core/src/models/core_schemas.rs)** - get_core_schemas() returns Vec<SchemaNode> for all 7 core schemas - Uses existing SchemaNode struct (no new types) - Task schema has 6 fields (status, priority, due_date, started_at, completed_at, assignee) - Simple schemas (text, date, header, code-block, quote-block, ordered-list) have no fields **Dynamic Spoke Table Detection (packages/core/src/db/surreal_store.rs)** - Added types_with_spoke_tables: HashSet<String> field to SurrealStore - Added has_spoke_table() method to check if a type needs a spoke table - Added build_spoke_table_cache() to derive spoke table needs from schema definitions - Schema type always has spoke table (structural) - Other types have spoke tables if their schema has fields.len() > 0 - Removed TYPES_WITH_SPOKE_TABLES constant entirely **Atomic Schema Operations (packages/core/src/db/surreal_store.rs)** - Added create_schema_node_atomic() for atomic schema creation + DDL execution - Transaction order: DDL FIRST, then CREATE hub + spoke - Matches update_schema_node_atomic() pattern for consistency **NodeService Integration (packages/core/src/services/node_service.rs)** - Updated create_node() to detect schema nodes and use atomic creation - Generates DDL via SchemaTableManager.generate_ddl_statements() - Ensures schema definition and spoke table are created together **SchemaTableManager Fixes (packages/core/src/services/schema_table_manager.rs)** - Changed to SCHEMAFULL (not SCHEMALESS) for proper field enforcement - Added TABLE keyword: "ON TABLE task" not "ON task" - Added FLEXIBLE to field definitions for user extensions - Changed index syntax: COLUMNS not FIELDS - Added option<> wrapping for optional fields - Added DEFAULT values for required fields with defaults - Added node field (reverse link to hub) for all spoke tables **Schema DDL Cleanup (packages/core/src/db/schema.surql)** - Removed task spoke table definitions (lines 42-59) - Kept schema spoke table (structural, not schema-derived) - Updated header comments to reflect dynamic generation **TypeScript Cleanup** - Deleted packages/desktop-app/scripts/init-schemas-via-proxy.ts (321 lines) - Removed dev:browser:init from package.json - Updated dev:browser to skip init step ## Testing Frontend: 1440 passed (same as baseline) Rust: 482 passed (16 ignored) - same as baseline ## Architecture Notes 8 core node types, 7 with schema entries: 1. task - has schema + spoke table 2-7. text, date, header, code-block, quote-block, ordered-list - schema only, no spoke tables 8. schema - NO schema entry (meta-type, structural spoke table in schema.surql) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove hardcoded VALID_NODE_TYPES, derive from schemas (Issue #691) Fixes pre-existing inconsistency where VALID_NODE_TYPES used underscores (code_block, quote_block, ordered_list) while actual node types use hyphens (code-block, quote-block, ordered-list). Instead of fixing the typos, removed the redundant hardcoded constant entirely. Valid node types are now derived from schema definitions at runtime, matching the approach used for TYPES_WITH_SPOKE_TABLES. Changes: - Remove VALID_NODE_TYPES constant and standalone validate_node_type fn - Rename build_spoke_table_cache -> build_schema_caches (returns both) - Add valid_node_types field to SurrealStore struct - Add validate_node_type() method to SurrealStore - Update constructors and bootstrap code to initialize both caches Benefits: - Single source of truth: schema definitions drive validation - No risk of underscore/hyphen typos - Automatically supports new schema types without code changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* Consolidate schema seeding with dynamic spoke table management (Issue #691) ## Summary - Create core_schemas.rs with get_core_schemas() returning Vec<SchemaNode> - Remove TYPES_WITH_SPOKE_TABLES hardcoded constant - derive from schema definitions - Add create_schema_node_atomic() for atomic schema creation + DDL sync - Update NodeService.create_node() to handle schema nodes atomically - Fix SchemaTableManager DDL generation (SCHEMAFULL, TABLE keyword, FLEXIBLE, COLUMNS) - Remove task spoke table DDL from schema.surql (now generated dynamically) - Delete init-schemas-via-proxy.ts TypeScript seeding script ## Key Changes **Core Definitions (packages/core/src/models/core_schemas.rs)** - get_core_schemas() returns Vec<SchemaNode> for all 7 core schemas - Uses existing SchemaNode struct (no new types) - Task schema has 6 fields (status, priority, due_date, started_at, completed_at, assignee) - Simple schemas (text, date, header, code-block, quote-block, ordered-list) have no fields **Dynamic Spoke Table Detection (packages/core/src/db/surreal_store.rs)** - Added types_with_spoke_tables: HashSet<String> field to SurrealStore - Added has_spoke_table() method to check if a type needs a spoke table - Added build_spoke_table_cache() to derive spoke table needs from schema definitions - Schema type always has spoke table (structural) - Other types have spoke tables if their schema has fields.len() > 0 - Removed TYPES_WITH_SPOKE_TABLES constant entirely **Atomic Schema Operations (packages/core/src/db/surreal_store.rs)** - Added create_schema_node_atomic() for atomic schema creation + DDL execution - Transaction order: DDL FIRST, then CREATE hub + spoke - Matches update_schema_node_atomic() pattern for consistency **NodeService Integration (packages/core/src/services/node_service.rs)** - Updated create_node() to detect schema nodes and use atomic creation - Generates DDL via SchemaTableManager.generate_ddl_statements() - Ensures schema definition and spoke table are created together **SchemaTableManager Fixes (packages/core/src/services/schema_table_manager.rs)** - Changed to SCHEMAFULL (not SCHEMALESS) for proper field enforcement - Added TABLE keyword: "ON TABLE task" not "ON task" - Added FLEXIBLE to field definitions for user extensions - Changed index syntax: COLUMNS not FIELDS - Added option<> wrapping for optional fields - Added DEFAULT values for required fields with defaults - Added node field (reverse link to hub) for all spoke tables **Schema DDL Cleanup (packages/core/src/db/schema.surql)** - Removed task spoke table definitions (lines 42-59) - Kept schema spoke table (structural, not schema-derived) - Updated header comments to reflect dynamic generation **TypeScript Cleanup** - Deleted packages/desktop-app/scripts/init-schemas-via-proxy.ts (321 lines) - Removed dev:browser:init from package.json - Updated dev:browser to skip init step ## Testing Frontend: 1440 passed (same as baseline) Rust: 482 passed (16 ignored) - same as baseline ## Architecture Notes 8 core node types, 7 with schema entries: 1. task - has schema + spoke table 2-7. text, date, header, code-block, quote-block, ordered-list - schema only, no spoke tables 8. schema - NO schema entry (meta-type, structural spoke table in schema.surql) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Remove hardcoded VALID_NODE_TYPES, derive from schemas (Issue #691) Fixes pre-existing inconsistency where VALID_NODE_TYPES used underscores (code_block, quote_block, ordered_list) while actual node types use hyphens (code-block, quote-block, ordered-list). Instead of fixing the typos, removed the redundant hardcoded constant entirely. Valid node types are now derived from schema definitions at runtime, matching the approach used for TYPES_WITH_SPOKE_TABLES. Changes: - Remove VALID_NODE_TYPES constant and standalone validate_node_type fn - Rename build_spoke_table_cache -> build_schema_caches (returns both) - Add valid_node_types field to SurrealStore struct - Add validate_node_type() method to SurrealStore - Update constructors and bootstrap code to initialize both caches Benefits: - Single source of truth: schema definitions drive validation - No risk of underscore/hyphen typos - Automatically supports new schema types without code changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Closes #691