MigrationConfig
class MigrationConfig
Configuration class for setting up migration steps and options.
MigrationConfig provides a DSL (Domain Specific Language) for configuring migration operations. It allows you to define migration steps, configure logging, and set up the execution sequence for data migration operations.
The configuration is used by the Migration class to create and execute migration workflows with proper progress tracking and error handling.
Basic Usage:
val migration = Migration {
// Configure logging (optional)
logger = MyCustomLogger()
// Define migration steps
step("Initialize database") {
database.createTables()
MigrationStepResult.CONTINUE
}
step("Migrate user data") {
migrateUsers()
MigrationStepResult.CONTINUE
}
step("Clean up old data") {
cleanupOldFiles()
MigrationStepResult.CONTINUE
}
}Content copied to clipboard
Advanced Usage with State Management:
val migration = Migration {
step("Load configuration") {
val config = loadMigrationConfig()
state["migrationConfig"] = config
logger.i("Configuration loaded: ${config.version}")
MigrationStepResult.CONTINUE
}
step("Validate prerequisites") {
val config = getValue<MigrationConfig>("migrationConfig")
if (config?.isValid() == true) {
MigrationStepResult.CONTINUE
} else {
logger.w("Prerequisites not met, aborting migration")
MigrationStepResult.ABORT
}
}
}Content copied to clipboard
Retry Logic Example:
val migration = Migration {
step("Download migration data") {
val retryCount = getValue<Int>("retryCount") ?: 0
if (retryCount >= 3) {
logger.e("Max retries exceeded")
throw RuntimeException("Failed to download after 3 attempts")
}
val success = downloadData()
if (success) {
MigrationStepResult.CONTINUE
} else {
state["retryCount"] = retryCount + 1
logger.w("Download failed, retry attempt ${retryCount + 1}")
MigrationStepResult.RERUN
}
}
}Content copied to clipboard