MigrationRunner

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:

  1. Read configVersion from the raw map (defaults to 1 if absent).

  2. If the file version is already at or above the target, return immediately.

  3. Create a backup of the source file as <filename>.v<version>.bak (only once per version).

  4. Find the migration where fromVersion == currentVersion, apply it, advance to toVersion.

  5. Repeat step 4 until the target version is reached.

  6. Set configVersion in 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

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun clear()

Removes all registered migrations from this runner.

Link copied to clipboard

Returns true if at least one migration has been registered.

Link copied to clipboard
fun migrate(rawMap: MutableMap<String, Any?>, currentVersion: Int, sourceFile: File? = null): MutableMap<String, Any?>

Migrates a raw configuration map from its detected version to currentVersion.

Link copied to clipboard
fun register(migration: ConfigMigration)

Registers a migration step with this runner.