Skip to main content

Module migrate

Module migrate 

Source
Expand description

Schema-evolution trait — Migrate.

Migrate is the API by which a Document type transforms older stored records into the current shape. The codec invokes migrate whenever a stored record’s type_version is less than the reader’s Document::VERSION.

Every T: Document is implicitly Migrate via the blanket impl at the bottom of this file. The default body of the inherent method Document::migrate returns Error::SchemaMigrationNotImplemented. Real types override Document::migrate to handle older versions; Migrate::migrate forwards to it.

M5 ships the trait and the decode-time dispatch only. The full “lazy migrate on read” runtime with mixed-version coexistence is M10’s milestone. The on-disk contract pinned here is permanent: type_version > T::VERSION is always Error::SchemaVersionFromFuture; type_version < T::VERSION always routes through migrate.

§Power-of-ten posture

  • Rule 5. The default body errors at the boundary, never silently returns a default value — silent migration failure would be the most dangerous outcome.
  • Rule 7. Override implementations propagate every fallible step via ?; the trait does not encourage unwrap.
  • Rule 9. Static dispatch only — <T as Migrate> is monomorphised in crate::codec::decode.

Traits§

Migrate
Static-dispatch shim trait so crate::codec::decode can write <T as Migrate>::migrate(...) without taking T: Migrate as an explicit bound on top of T: Document.