Skip to main content

Module migrate

Module migrate 

Source
Expand description

Safe schema upgrade path for vault files.

When tsafe loads a vault whose _schema version is older than the current one, migrate::run applies transformations in order and writes the upgraded file back to disk atomically. A snapshot is taken before any mutation so there is always a rollback point.

Adding a new migration:

  1. Increment CURRENT_SCHEMA to the new version string.
  2. Push a new Migration entry into the MIGRATIONS slice.
  3. Write a pure fn(VaultFile) -> SafeResult<VaultFile> that performs the structural change. No I/O inside the transform function.

Constants§

CURRENT_SCHEMA
The schema version this build writes.

Functions§

run
Check whether file needs upgrading and, if so, apply all pending migrations, write the result back to path, and return true. Returns false when the schema is already current. Returns Err when the schema is unknown or a transform fails.