Skip to main content

Migrations

Migrations live in crates/surreal-memory/src/storage/migrations/mod.rs and are applied automatically on startup, recorded in schema_version with a checksum.

The schema/struct sync rule​

Every persisted field needs a matching DEFINE FIELD. SCHEMAFULL tables reject anything undeclared, and this has caused production failures — for example TaskStream.auto_summarize was added to the struct without a migration and create_task_stream failed at runtime.

Adding a field:

  1. Add it to the struct with #[serde(default)] for backward compatibility.
  2. Add a migration in the same change, not a follow-up.
  3. Test in both embedded and server mode.

Current migrations​

VersionName
1initial_entity_relation_schema
2scoped_memory_table
3task_stream_table
4memory_history_table
5hnsw_vector_indexes
6mindmap_table_and_fulltext_indexes
7task_stream_auto_summarization_fields
8memory_metadata_flexible
9–13Mindmap schema refinements
14legacy_enum_string_normalization (repair)
15enum_fields_as_strings
16palace_drawers_table
17dynamic_embedding_index_metadata
18task_stream_scope_unique_index
19task_step_table
20durable_operation_ledger
21embedding_executor_journal

Most migrations are SQL. Version 14 is a repair migration — it runs Rust code to normalize legacy enum values written as single-key objects ({ Active: {} }) into strings. It must precede v15, which tightens those fields from any to string; the reverse order would reject the existing rows.