ConfigMigration

interface ConfigMigration

Defines a single-step configuration migration from one version to the next.

Implementations transform a raw YAML map in-place (or return a new map) to upgrade the configuration schema from fromVersion to toVersion. Migrations are registered with MigrationRunner and executed in chain order during YamlConfigManager.load.

Each migration should handle exactly one version increment (e.g., v1 to v2). The MigrationRunner chains multiple migrations together automatically.

Example -- renaming a property from v1 to v2:

object MigrateV1ToV2 : ConfigMigration {
override val fromVersion = 1
override val toVersion = 2

override fun migrate(map: MutableMap<String, Any?>): MutableMap<String, Any?> {
// Rename "serverPort" to "port"
map["port"] = map.remove("serverPort")
// Add a new field with a default
map.putIfAbsent("maxConnections", 100)
return map
}
}

// Register the migration
YamlConfigManager.registerMigration(MyConfig::class, MigrateV1ToV2)

Since

1.0

See also

Properties

Link copied to clipboard
abstract val fromVersion: Int

The schema version this migration upgrades from.

Link copied to clipboard
abstract val toVersion: Int

The schema version this migration upgrades to. Typically fromVersion + 1.

Functions

Link copied to clipboard
abstract fun migrate(map: MutableMap<String, Any?>): MutableMap<String, Any?>

Transforms the raw configuration map from fromVersion to toVersion.