Repository navigation
Add schema field rename with property data migration - #1174
Conversation
Renames a field in a schema definition and migrates all existing node instances:
- SurrealStore.rename_schema_field: fetches nodes of the type, renames the
key in the namespace object in Rust, and writes back each updated node
- NodeService.rename_schema_field: validates source/destination fields exist,
calls store migration, then updates schema definition
- UpdateSchemaParams.rename_fields: [{from, to}] array, processed before
add/remove so subsequent operations see post-rename schema state
- update_schema agent tool: exposes rename_fields with clear description
- 4 integration tests covering schema update, error cases, and data migration
Co-Authored-By: Claude <[email protected]>
Code Review SummaryThis is a net-positive change that solves a real data-loss problem. The implementation is readable, well-tested for the common cases, and the layering (store → service → handler → tool) is consistent with the existing codebase architecture. There are no security issues or critical regressions. Three issues need attention before merge: a critical gap in the rename-validation/playbook-guard flow (renames bypass both schema validation and playbook impact checks), a moderate correctness hole around duplicate FindingsCritical Issues[Critical/Blocker] Renames bypass schema validation and playbook impact check
The fix is to move the playbook impact check (and potentially validation) ahead of Phase 1, or to run a targeted impact check per rename before executing it. Suggested Improvements[Improvement] Duplicate
[Improvement] Non-atomic behavior is documented as atomic in two places
None of this is atomic: step 2 (data migration) is N individual UPDATE statements with no transaction, and step 3 (schema definition update) is a separate write that can fail after all node data is already migrated. For a greenfield project with no production data this is acceptable, but the documentation actively misleads: a caller reading the doc comment would believe a crash is safe, when in reality a crash between node 5 and node 6 leaves the graph inconsistent. Remove the word "atomic" from all three locations and replace with accurate language (e.g., "sequential; if the schema definition update fails after data migration, the data is already correct and the schema update can be retried"). [Improvement]
[Improvement]
NitpicksNit: Nit: Nit: Nit: |
…and atomicity docs - Move playbook impact check before Phase 1 renames execute so a blocked rename cannot partially migrate node data before the guard fires - Add seen_sources check alongside seen_destinations to reject duplicate `from` values within a single rename batch - Remove inaccurate "atomically" from node_service doc comment and tools.rs description; the two-step migrate+update is sequential, not atomic - Add `additionalProperties: false` to rename_fields item schema in tools.rs - Tighten schema_test assertion: old_field must be absent (is_none) after rename, not merely null Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Review feedback addressed (commit 9f95a67)✅ Addressed (🔴 Critical)Playbook guard ran after renames — Moved ✅ Addressed (🟡 Important × 2)Duplicate Inaccurate "atomically" documentation — Removed from ✅ Addressed (🟢 Suggestions)
⏭️ Skipped
|
* Add schema field rename with property data migration (closes #1088) Renames a field in a schema definition and migrates all existing node instances: - SurrealStore.rename_schema_field: fetches nodes of the type, renames the key in the namespace object in Rust, and writes back each updated node - NodeService.rename_schema_field: validates source/destination fields exist, calls store migration, then updates schema definition - UpdateSchemaParams.rename_fields: [{from, to}] array, processed before add/remove so subsequent operations see post-rename schema state - update_schema agent tool: exposes rename_fields with clear description - 4 integration tests covering schema update, error cases, and data migration Co-Authored-By: Claude <[email protected]> * Address review: fix playbook guard ordering, duplicate-source check, and atomicity docs - Move playbook impact check before Phase 1 renames execute so a blocked rename cannot partially migrate node data before the guard fires - Add seen_sources check alongside seen_destinations to reject duplicate `from` values within a single rename batch - Remove inaccurate "atomically" from node_service doc comment and tools.rs description; the two-step migrate+update is sequential, not atomic - Add `additionalProperties: false` to rename_fields item schema in tools.rs - Tighten schema_test assertion: old_field must be absent (is_none) after rename, not merely null Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude <[email protected]>
Summary
SurrealStore::rename_schema_fieldthat fetches all nodes of a type, rekeys the field in the namespace object in Rust, and writes each updated node back individuallyNodeService::rename_schema_fieldthat validates source/destination field existence, runs data migration, then updates the schema definitionrename_fields: [{from, to}]toUpdateSchemaParams(processed before add/remove so subsequent operations see post-rename schema state) and to theupdate_schemaagent toolCloses #1088
🤖 Generated with Claude Code