Skip to main content

Module document_migration

Module document_migration 

Source
Expand description

All-at-once, reversible migration to the native binary document body (PRD-1398, ADR-0063).

A legacy DOCUMENT store keeps two copies of every document — a plain-JSON body and the materialised promoted columns. The single-source slices (#1402/#1403) make the binary body the one source of truth, but existing stores still hold plain-JSON bodies with promoted columns. This tool performs the cutover, modelled on the maintainer’s explicit safety margin: the canonical data is never touched until the very end.

The migration is all-at-once but reversible:

  1. Read every document from the source store (untouched, read-only).
  2. Build a fresh store in new files alongside the source, rewriting each document into the native binary container (crate::document_body).
  3. Auto-CREATE INDEX for every previously-promoted field so queries that relied on the implicit promoted-column filter stay fast — avoiding a silent post-deploy performance regression.
  4. Verify document counts match per collection; any mismatch aborts the migration before the swap, leaving the source store untouched.
  5. Atomically swap the new files into place and retain the old files as the rollback point.

The unit of migration is a store directory (the directory that holds the db.rdb data file and its sibling artifacts — WAL, snapshots, audit log). Swapping whole directories with rename(2) is atomic on POSIX and lets the pre-migration directory survive untouched as the rollback point.

Structs§

CollectionMigration
Per-collection outcome of a migration.
MigrationReport
Summary of a completed, swapped migration.

Functions§

migrate_store_to_binary_body
Migrate the DOCUMENT collections of the store in store_dir to the native binary body, reversibly.