Skip to main content

Module backup

Module backup 

Source
Expand description

Backup and recovery: dump every registered model’s rows to JSON, load them back.

The two halves are symmetric. dump walks migrate::registered_models(), runs SELECT * FROM <table> for each, and dispatches per column’s SqlType to read every value out as a serde_json::Value. load reads the JSON back and inserts each row through sqlx::query with the same per-column dispatch on the binding side.

The on-disk format is one JSON document with a small envelope:

{
  "umbral_dump_version": "1",
  "exported_at": "2026-05-30T17:00:00Z",
  "models": [
    { "table": "post", "rows": [{"id": 1, "title": "..."}] },
    { "table": "tag",  "rows": [{"id": 1, "name": "..."}] }
  ]
}

§v1 scope

  • Every SqlType variant in the M3 catalogue: integer widths, floats, bool, text, date/time/timestamptz, uuid, plus their nullable forms.
  • One-shot dump + load. No partial dumps, no streaming.
  • Order-independent: load doesn’t assume a particular model sequence; rows insert into existing tables (the schema must be present, which is what umbral-cli migrate is for).

§Deferred

  • Schema-snapshot embedding for forward-compat (the dump captures data only; the receiver needs a compatible schema).
  • Streaming for very large databases.
  • Selective dump / load with model filters.

Structs§

Dump
The on-disk envelope. models order is the order dump wrote them in (sorted by table name for determinism). exported_at is captured at dump time for traceability; load doesn’t read it.
LoadReport
What load did. Tables present in the dump but not in the current schema land in skipped_tables (not an error; the dump might be from a richer schema).
ModelDump
One table’s worth of rows. The table field carries the SQL table name (Model::TABLE), not the Rust struct name, so a load against a schema that ran #[umbral(table = "...")] overrides still finds the right destination.

Enums§

BackupError
Errors the dump / load pipeline can produce.

Functions§

dump
Dump every registered model’s rows to a Dump value. The ambient pool (published by App::build) is the source.
dump_to_path
Convenience: dump and write the JSON to path.
load
Load a Dump back into the database. Schema must already exist (run umbral-cli migrate first). Rows insert via sqlx::query with per-column type dispatch; the ambient pool is the target.
load_from_path
Convenience: read the JSON from path and load it.