Migration
A migration framework that executes a series of migration steps in sequence.
The Migration class provides a structured way to perform data migration operations with progress tracking, error handling, and step control flow. Each migration step can decide whether to continue to the next step, rerun the current step, or abort the entire migration process.
Key Features:
Sequential Execution: Steps are executed in the order they are defined
Progress Tracking: Emits progress events throughout the migration process
Error Handling: Captures and reports errors with step context
Step Control Flow: Steps can control execution flow (continue, rerun, abort)
Execution Context: Provides shared state and utilities across steps
Usage:
val migration = Migration {
logger = MyLogger()
step("Initialize database") {
// Initialize database schema
MigrationStepResult.CONTINUE
}
step("Migrate user data") {
// Migrate user data with retry logic
if (migrationSuccessful) {
MigrationStepResult.CONTINUE
} else {
MigrationStepResult.RERUN
}
}
step("Clean up old data") {
// Clean up old data
MigrationStepResult.CONTINUE
}
}
migration.migrate(context).collect { progress ->
when (progress) {
is MigrationProgress.Started -> println("Migration started")
is MigrationProgress.InProgress -> println("Step ${progress.currentStep}/${progress.totalSteps}: ${progress.message}")
is MigrationProgress.StepCompleted -> println("Completed: ${progress.step.description}")
is MigrationProgress.Success -> println("Migration completed: ${progress.message}")
is MigrationProgress.Error -> println("Migration failed: ${progress.error.message}")
}
}Parameters
The migration configuration containing steps and settings