Event schema versioning and upcasting support #325
Labels
No labels
adr
automated
bug
chore
dependencies
documentation
enhancement
epic
github-actions
P1-high
P2-medium
P3-low
release
research
rust
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jwilger/eventcore#325
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
When event schemas evolve over time (new fields, changed types, removed fields), previously persisted events may fail to deserialize against the updated Rust types. Currently, eventcore stores events as JSON blobs via serde with no built-in versioning, schema registry, or upcasting mechanism. If a variant's structure changes incompatibly,
serde_json::from_strfails hard during stream replay.For additive changes (new fields with defaults), applications can use
#[serde(default)]at the application layer. But for non-backwards-compatible changes (field removal, type changes, semantic incompatibility), there's no path forward without manual workarounds.Desired Behavior
An upcasting system that allows applications to:
CommandLogic::applyorProjectorhandlersApplication code only handles the latest event version. Old versions are transparently transformed.
Possible Approaches
event_typecolumn already exists but isn't used for version routing)fn(serde_json::Value) -> serde_json::Valuetransformations keyed by (event_type, from_version, to_version)Context
This came up in a consuming project (stochastic_macro) that follows outside-in TDD, where event fields are added incrementally across implementation slices. Additive changes work with
#[serde(default)], but non-backwards-compatible changes are currently blocked.Completed in #343 and #344 — ADR-0035 documents enum variant approach for schema evolution, and Event::event_type_name() added for stable storage.