step

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

Adds a migration step with a description and action.

This is the primary method for defining migration steps within the configuration DSL. Each step will be executed in the order it's added to the configuration.

Examples:

Simple Step:

step("Clear application cache") {
clearCache()
MigrationStepResult.CONTINUE
}

Step with Conditional Logic:

step("Migrate user preferences") {
val userCount = getUserCount()
if (userCount 0) {
migrateUserPreferences()
MigrationStepResult.CONTINUE
} else {
logger.i("No users to migrate, skipping step")
MigrationStepResult.CONTINUE
}
}

Step with State Management:

step("Process migration batch") {
val batchSize = getValue<Int>("batchSize") ?: 100
val processed = processBatch(batchSize)
state["processedCount"] = processed
MigrationStepResult.CONTINUE
}

Parameters

description

A descriptive message explaining what this step does

action

The suspend function containing the migration logic


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

Adds a migration step with an auto-generated description.

This method is provided for backward compatibility and convenience. It creates a migration step with a generic description based on the step's position in the sequence.

Note: It's recommended to use the version with an explicit description for better progress tracking and debugging.

Example:

step {
performMigrationTask()
MigrationStepResult.CONTINUE
}
// Creates a step with description "Migration step 1", "Migration step 2", etc.

Parameters

step

The suspend function containing the migration logic


fun step(step: MigrationStep)

Adds a pre-created MigrationStep instance to the configuration.

This method allows you to add MigrationStep instances that were created outside of the configuration DSL. This is useful for reusing common migration steps or when you need more complex step creation logic.

Examples:

Reusable Step:

val databaseInitStep = MigrationStep("Initialize database") {
initializeDatabase()
MigrationStepResult.CONTINUE
}

Migration {
step(databaseInitStep) // Reuse the step
step("Additional migration") { /* ... */}
}

Conditional Step Addition:

Migration {
if (needsSpecialMigration) {
step(createSpecialMigrationStep())
}
step("Standard migration") { /* ... */}
}

Parameters

step

A pre-created MigrationStep instance