Interface MigrationResult
- All Known Implementing Classes:
MigrationResult.Failure, MigrationResult.Success
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:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classBuilder for creating migration results incrementally.static final recordRepresents a failed migration result.static final recordRepresents a single migration step that was applied.static final recordRepresents a successful migration result. -
Method Summary
Modifier and TypeMethodDescriptionstatic MigrationResult.BuilderCreates a new result builder.data()Returns the migrated data.duration()Returns the total duration of the migration operation.error()Returns the error if the migration failed.static MigrationResultfailure(int fromVersion, int failedAtVersion, List<MigrationResult.MigrationStep> stepsCompleted, Duration duration, Map<String, Object> data, MigrationException error) Creates a failed migration result.intReturns the version the data was at before migration.booleanReturns whether the migration completed successfully.static MigrationResultnoMigrationNeeded(int version, Map<String, Object> data) Creates a result indicating no migration was needed.steps()Returns the list of migration steps that were applied.static MigrationResultsuccess(int fromVersion, int toVersion, List<MigrationResult.MigrationStep> steps, Duration duration, Map<String, Object> data) Creates a successful migration result.intReturns the version the data is at after migration.
-
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
List<MigrationResult.MigrationStep> 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
-
error
Optional<MigrationException> 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 versiontoVersion- the target versionsteps- the migration steps appliedduration- the total durationdata- the migrated data- Returns:
- a successful result
-
noMigrationNeeded
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 versionfailedAtVersion- the version where migration failedstepsCompleted- the steps that completed before failureduration- the duration until failuredata- the data state at failureerror- the exception that caused the failure- Returns:
- a failed result
-
builder
Creates a new result builder.- Parameters:
fromVersion- the starting versiondata- the data being migrated- Returns:
- a new builder
-