Skip to main content

Module migrate

Module migrate 

Source
Expand description

Stepwise schema migration for block-stored JSON.

When a block’s crate::Block::version is bumped, every load comparing the stored version on a JSON entry to the current version triggers apply_migrations, which walks each integer version between them calling crate::Block::migrate once per step. Authors write single-version-step migrators only; the framework chains them.

§Wire-format version

The JSON envelope of a block entry stores version: u32 next to type / id / value (explicit per-item versions beat implicit ones). Missing version is treated as 1 (the initial baseline).

Functions§

apply_migrations
Apply every step between stored and block.version() in order. Each step gets the previous step’s output. Already-current values (or future values stored by a newer process) short-circuit.
read_stored_version
Read the stored version off a {type, id, value, version?} envelope. Missing / non-integer falls back to 1 so legacy streams that pre-date version-stamping just sail through unchanged (their migrate(1, …) for blocks at v1 is a no-op).