MigrationStep
interface MigrationStep
Represents a single migration step with its description and action.
A MigrationStep encapsulates both the metadata (description) and the logic (execute function) for a single migration operation. Steps are executed sequentially by the Migration framework, and each step can control the migration flow through its return value.
Implementation Patterns:
Simple Step:
val step = MigrationStep("Clear cache") {
clearApplicationCache()
MigrationStepResult.CONTINUE
}Content copied to clipboard
Step with State Sharing:
val loadConfigStep = MigrationStep("Load configuration") {
val config = loadConfiguration()
state["config"] = config
MigrationStepResult.CONTINUE
}
val applyConfigStep = MigrationStep("Apply configuration") {
val config = getValue<Configuration>("config")
applyConfiguration(config)
MigrationStepResult.CONTINUE
}Content copied to clipboard
Step with Error Handling:
val migrationStep = MigrationStep("Migrate user data") {
try {
migrateUserData()
MigrationStepResult.CONTINUE
} catch (e: Exception) {
logger.e("Migration failed", e)
throw MigrationException("Failed to migrate user data", e)
}
}Content copied to clipboard