C++ / fmt (pull_request) Failing after 4s
C++ / build (pull_request) Failing after 12s
JS/TS / fmt (pull_request) Successful in 15s
JS/TS / lint (pull_request) Successful in 15s
C++ / clang-tidy (pull_request) Failing after 33s
Python / static (pull_request) Failing after 36s
Rust / fmt (pull_request) Successful in 1m14s
Rust / build (pull_request) Successful in 1m49s
Rust / clippy (pull_request) Successful in 1m33s
Python / verify (pull_request) Successful in 2m10s
39 lines
1.2 KiB
C++
39 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <QJsonObject>
|
|
#include <QStringList>
|
|
|
|
namespace ZShell::config {
|
|
|
|
// A single migration rule: move the value stored at the dotted `from` path
|
|
// to the dotted `to` path, then delete the old key (and any parent objects
|
|
// left empty).
|
|
//
|
|
// Rules are applied to the raw JSON file on every load, before the schema
|
|
// loads it. They are idempotent: once the old key is gone the rule never
|
|
// fires again, so no version stamping is needed. Old rules can stay in the
|
|
// table forever.
|
|
//
|
|
// WARNING: the target path must exist in the schema (i.e. a ConfigObject
|
|
// property somewhere in the tree). If it does not, the migrated value is
|
|
// loaded as an unknown key and silently dropped on the next save.
|
|
struct ConfigMigrationRule {
|
|
QString from;
|
|
QString to;
|
|
};
|
|
|
|
// Helper for writing rules: migrate("general.color.foo", "display.bar.foo")
|
|
inline ConfigMigrationRule migrate(const QString& from, const QString& to) {
|
|
return {from, to};
|
|
}
|
|
|
|
class ConfigMigrations {
|
|
public:
|
|
[[nodiscard]] static const QList<ConfigMigrationRule>& rules();
|
|
|
|
// Applies all rules to `json`, returning the migrated object.
|
|
[[nodiscard]] static QJsonObject apply(const QJsonObject& json);
|
|
};
|
|
|
|
} // namespace ZShell::config
|