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

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

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

See also

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

Logger instance used for migration progress and error reporting.

Functions

Link copied to clipboard
fun step(step: MigrationStep)

Adds a pre-created MigrationStep instance to the configuration.

fun step(step: suspend ExecutionContext.() -> MigrationStepResult)

Adds a migration step with an auto-generated description.

fun step(description: String, action: suspend ExecutionContext.() -> MigrationStepResult)

Adds a migration step with a description and action.