Interface MigrationResult

All Known Implementing Classes:
MigrationResult.Failure, MigrationResult.Success

public sealed interface MigrationResult permits MigrationResult.Success, MigrationResult.Failure

Encapsulates the outcome of a configuration migration operation.

A migration result contains information about whether the migration succeeded, which versions were involved, timing information, and details about each individual migration step that was applied.

Success vs Failure

Use isSuccess() to check if the migration completed successfully:

MigrationResult result = migrator.migrate(configPath, 5);
if (result.isSuccess()) {
    System.out.println("Migrated to version " + result.toVersion());
} else {
    System.err.println("Migration failed: " + result.error().getMessage());
}

Migration Steps

For successful migrations, steps() provides details about each migration that was applied:

for (MigrationStep step : result.steps()) {
    System.out.printf("Applied migration %d -> %d: %s%n",
        step.fromVersion(), step.toVersion(), step.description());
}
See Also:
  • Method Details

    • isSuccess

      boolean isSuccess()
      Returns whether the migration completed successfully.
      Returns:
      true if all migrations were applied successfully
    • fromVersion

      int fromVersion()
      Returns the version the data was at before migration.
      Returns:
      the starting version
    • toVersion

      int toVersion()

      Returns the version the data is at after migration.

      For successful migrations, this is the target version. For failed migrations, this is the last successfully applied version.

      Returns:
      the ending version
    • steps

      Returns the list of migration steps that were applied.

      For failed migrations, this includes only the steps that completed successfully before the failure.

      Returns:
      an unmodifiable list of migration steps
    • duration

      Duration duration()
      Returns the total duration of the migration operation.
      Returns:
      the duration from start to completion
    • data

      Map<String,Object> data()

      Returns the migrated data.

      For successful migrations, this is the fully transformed data. For failed migrations, this may be partial or the original data.

      Returns:
      the data map
    • error

      Returns the error if the migration failed.
      Returns:
      an Optional containing the exception if failed, empty if successful
    • success

      static MigrationResult success(int fromVersion, int toVersion, List<MigrationResult.MigrationStep> steps, Duration duration, Map<String,Object> data)
      Creates a successful migration result.
      Parameters:
      fromVersion - the starting version
      toVersion - the target version
      steps - the migration steps applied
      duration - the total duration
      data - the migrated data
      Returns:
      a successful result
    • noMigrationNeeded

      static MigrationResult noMigrationNeeded(int version, Map<String,Object> data)
      Creates a result indicating no migration was needed.
      Parameters:
      version - the current version (which equals the target)
      data - the unchanged data
      Returns:
      a success result with no steps
    • failure

      static MigrationResult failure(int fromVersion, int failedAtVersion, List<MigrationResult.MigrationStep> stepsCompleted, Duration duration, Map<String,Object> data, MigrationException error)
      Creates a failed migration result.
      Parameters:
      fromVersion - the starting version
      failedAtVersion - the version where migration failed
      stepsCompleted - the steps that completed before failure
      duration - the duration until failure
      data - the data state at failure
      error - the exception that caused the failure
      Returns:
      a failed result
    • builder

      static MigrationResult.Builder builder(int fromVersion, Map<String,Object> data)
      Creates a new result builder.
      Parameters:
      fromVersion - the starting version
      data - the data being migrated
      Returns:
      a new builder