Migration Runner
Executes an ordered chain of ConfigMigration steps to upgrade a raw YAML map from an older schema version to the current version.
The runner maintains a sorted list of migrations and applies them sequentially, starting from the file's detected version (read from the configVersion key, defaulting to 1) and ending at the target version.
Chaining algorithm:
Read
configVersionfrom the raw map (defaults to1if absent).If the file version is already at or above the target, return immediately.
Create a backup of the source file as
<filename>.v<version>.bak(only once per version).Find the migration where
fromVersion == currentVersion, apply it, advance totoVersion.Repeat step 4 until the target version is reached.
Set
configVersionin the map to the target version.
If a gap exists in the migration chain (no migration for a given version), an IllegalStateException is thrown listing the available migrations.
Example:
val runner = MigrationRunner()
runner.register(MigrateV1ToV2)
runner.register(MigrateV2ToV3)
// Migrates from v1 -> v2 -> v3, creating config.yml.v1.bak
val upgraded = runner.migrate(rawMap, targetVersion = 3, sourceFile = configFile)Since
1.0
See also
Functions
Returns true if at least one migration has been registered.
Migrates a raw configuration map from its detected version to currentVersion.
Registers a migration step with this runner.