Skip to main content

Module evolution

Module evolution 

Source
Expand description

How a resource’s storage changes between versions of its app.

A record stores the schema version it was written at under one key (VERSION_KEY, read by stored_version); #[resource(version = N, migrate = path)] declares the current one and how to bring an older document up to it (rewrite, after its derived steps). A document that does not read as the model is Unreadable: views show why and actions report it, and stale state is never shown as current.

Structs§

Unreadable
A document that does not read as its resource: what a view shows in place of stale state, and why each action is unavailable.

Constants§

VERSION_KEY
The root key a document’s schema version is stored under, when it is past the first. Every document keeps it here: an app’s record, a settings document, a tilo-doc page.

Functions§

check_version
Whether doc holds R at a version this build reads: its own or an older one, whose chain of steps stops short and is brought up before it opens. A newer version only adds fields and containers to a type, so this build’s fields are all still there and it reads them as far as it knows the record.
copy_into
Write what the record from holds into the record to, another record of the same kind and storage version kept elsewhere: what a record moving from one store to another takes along. Every field is copied as it is stored, scalars with their types, maps, lists and texts; the record’s own identity (its tilo: keys other than VERSION_KEY) stays to’s. A map or text to already holds at a key is written into rather than replaced, so what another writer adds to it concurrently is kept.
fixture
Write the keys of the JSON object shape into the map obj as an older version of an app stored them: what a migration’s test builds the document it migrates from. An object is a map, an array a list, a string, a boolean and a number are scalars (an integer as Int), null is a null scalar, and {"$text": "…"} is a text object holding the string.
needs_migrate
Whether doc is older than R: its chain of steps stops short of R’s version, so it is brought up (crate::founding::bring_up) before it is read.
read_checked
Read R from doc, or say why it does not read.
rewrite
The app’s own rewrite of the record scope names for version, from the version from it stood at, by migration (its #[resource(migrate = ..)]): once, as one housekeeping change after the record’s step to version, made by an actor and at a time derived from the record, its workspace, the version and the heads it starts from, so two holders rewriting the same history make the same change. It is decided as any write of the record’s. A rewrite rewrites by key and never inserts list elements, so two holders rewriting apart converge on one item each. Whether it changed anything.
step
The step that brings the record scope names to version: the change every holder makes alike, under an actor derived from the record, its workspace and the version alone, at time zero, writing the version key and nothing else. before holds exactly the link it follows, the record’s founding for the first version and the step to the version before otherwise, so the chain a record stands on is one every holder derives (crate::founding::chain), however its content went on meanwhile.
stored_version
The schema version doc was written at: 1 when it names none.
write_version
Record that doc is at version (nothing for the first version, so documents of apps that never changed their storage stay as they are).
write_version_at
write_version of the document whose root is at.