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
}

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
}

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)
}
}

See also

Properties

Link copied to clipboard
abstract var description: String

The human-readable description of this migration step.

Functions

Link copied to clipboard
abstract suspend fun execute(context: ExecutionContext): MigrationStepResult

Executes the migration step with the provided execution context.