Repository navigation
Description
Overview
Renaming a schema field requires two coordinated operations: updating the schema definition AND migrating all existing node instances to rekey their stored property data. Currently only the schema definition side is possible (via `update_schema` remove+add), which orphans existing data.
Problem Statement
When a user renames a field (e.g. `old_name` → `new_name` on a `project` schema):
- The schema definition must be updated (field renamed)
- All existing nodes of that type must have their `properties.old_name` rewritten to `properties.new_name`
Without step 2, existing node instances silently lose their data — the value stays in the DB under the old key but the schema no longer maps to it, so the UI shows the field as empty.
The current workaround (remove field + add field with new name) gives a clean schema but orphans all existing property values under the old key.
Proposed Solution
Phase 1: Database operation
Add an atomic rename operation to `SurrealStore` that executes:
```sql
UPDATE node
SET properties.new_name = properties.old_name
WHERE node_type = $type AND properties.old_name != NONE;
UPDATE node
SET properties = object::remove(properties, 'old_name')
WHERE node_type = $type;
```
Expose via `NodeService` as `rename_schema_field(type_id, from, to)`.
Phase 2: Schema definition update
Update the schema node's field list atomically with the data migration (same transaction or sequential with error rollback).
Phase 3: Agent tool
Add `rename_fields` parameter to `update_schema` agent tool:
```json
{
"schema_id": "project",
"rename_fields": [{ "from": "old_name", "to": "new_name" }]
}
```
Acceptance Criteria
- `SurrealStore` has a `rename_schema_field(type_id, from, to)` method that rekeys property data for all nodes of the given type
- Schema definition is updated atomically with the data migration
- `update_schema` MCP handler accepts `rename_fields: [{from, to}]` parameter
- `update_schema` agent tool exposes `rename_fields` parameter with clear description
- Existing node instances retain their values after a rename
- Tests pass (`bun run test:all`)
- Code passes `bun run quality:fix`
Technical Specifications
Reference Files
- SurrealStore: `packages/core/src/db/surreal_store.rs` — add rename operation
- NodeService: `packages/core/src/services/node_service.rs` — expose rename via service layer
- MCP schema handler: `packages/core/src/mcp/handlers/schema.rs` — `UpdateSchemaParams` struct (line ~251), `handle_update_schema` (line ~462)
- Agent tool: `packages/agent/src/local_agent/tools.rs` — `def_update_schema()`, `exec_update_schema()`
Implementation Details
- The rename must be atomic or transactional — partial failure (schema updated but data not migrated) would leave the graph in an inconsistent state
- Properties are stored namespaced: `{ "project": { "field": value } }` — the rename query must target the correct namespace
- Multiple renames in one call should be supported (array of `{from, to}` pairs)
- Renaming to an existing field name should be rejected with a clear error
Non-Goals
- Changing a field's type (remains unsupported — remove + add required)
- Renaming the schema type ID itself
Activity
Address review feedback on #1089
Unify agent guidance into single source of truth (#1089) (#1129)
malibio commentedon May 18, 2026
Frontend baseline: 129 test files, 3921 tests passed
Add schema field rename with property data migration (#1174)
Unify agent guidance into single source of truth (#1089) (#1129)
Add schema field rename with property data migration (#1174)