Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
PhosphorConfig::MigrationRunner Class Reference

Executes a Schema's migration chain against a JSON document. More...

#include <phosphor-config/include/PhosphorConfig/MigrationRunner.h>

Public Member Functions

 MigrationRunner (const Schema &schema)
 
 MigrationRunner (Schema &&)=delete
 Forbid construction from a temporary Schema — the runner stores a const reference, which would dangle the moment the temporary expires.
 
void runInMemory (QJsonObject &root) const
 Apply the full migration chain in memory.
 
bool runOnFile (const QString &jsonPath) const
 Read the file at jsonPath, run the chain, and — if the version advanced — atomically write the result back.
 
int readVersion (const QJsonObject &root) const
 Current version persisted in root, or 1 if unset / invalid.
 
void stampVersion (QJsonObject &root) const
 Stamp root with the schema's current version.
 

Detailed Description

Executes a Schema's migration chain against a JSON document.

Typical use: call runOnFile() once at startup, before opening a JsonBackend against the same path. The runner is idempotent — if the on-disk version already matches Schema::version it returns without rewriting the file.

Constructor & Destructor Documentation

◆ MigrationRunner() [1/2]

PhosphorConfig::MigrationRunner::MigrationRunner ( const Schema schema)
explicit

◆ MigrationRunner() [2/2]

PhosphorConfig::MigrationRunner::MigrationRunner ( Schema &&  )
explicitdelete

Forbid construction from a temporary Schema — the runner stores a const reference, which would dangle the moment the temporary expires.

Callers must own the schema for the runner's full lifetime.

Member Function Documentation

◆ readVersion()

int PhosphorConfig::MigrationRunner::readVersion ( const QJsonObject &  root) const

Current version persisted in root, or 1 if unset / invalid.

◆ runInMemory()

void PhosphorConfig::MigrationRunner::runInMemory ( QJsonObject &  root) const

Apply the full migration chain in memory.

Steps whose fromVersion matches the current Schema::versionKey are invoked in declared order; each step MUST bump the version by one. On a bump mismatch the chain aborts and an error is logged.

◆ runOnFile()

bool PhosphorConfig::MigrationRunner::runOnFile ( const QString &  jsonPath) const

Read the file at jsonPath, run the chain, and — if the version advanced — atomically write the result back.

Returns true on success, on "nothing to do", or on "file doesn't exist" (fresh install). Returns false only on parse or write errors.

Not safe against concurrent writers — the read-migrate-write sequence has no file lock. Assumes single-process single-user desktop-config usage; a second process mutating the file between our read and our atomic rename would silently have its edits overwritten.

◆ stampVersion()

void PhosphorConfig::MigrationRunner::stampVersion ( QJsonObject &  root) const

Stamp root with the schema's current version.


The documentation for this class was generated from the following file: