mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-31 20:51:26 +00:00
Fix Version Comparison Logic (#18616)
This commit is contained in:
parent
6fa03ee66a
commit
b6812f732f
@ -148,7 +148,8 @@ public class MigrationWorkflow {
|
|||||||
List<MigrationFile> availableMigrations) {
|
List<MigrationFile> availableMigrations) {
|
||||||
LOG.debug("Filtering Server Migrations");
|
LOG.debug("Filtering Server Migrations");
|
||||||
executedMigrations = migrationDAO.getMigrationVersions();
|
executedMigrations = migrationDAO.getMigrationVersions();
|
||||||
currentMaxMigrationVersion = executedMigrations.stream().max(String::compareTo);
|
currentMaxMigrationVersion =
|
||||||
|
executedMigrations.stream().max(MigrationWorkflow::compareVersions);
|
||||||
List<MigrationFile> applyMigrations;
|
List<MigrationFile> applyMigrations;
|
||||||
if (!nullOrEmpty(executedMigrations) && !forceMigrations) {
|
if (!nullOrEmpty(executedMigrations) && !forceMigrations) {
|
||||||
applyMigrations = getMigrationsToApply(executedMigrations, availableMigrations);
|
applyMigrations = getMigrationsToApply(executedMigrations, availableMigrations);
|
||||||
@ -182,6 +183,45 @@ public class MigrationWorkflow {
|
|||||||
return processes;
|
return processes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int compareVersions(String version1, String version2) {
|
||||||
|
int[] v1Parts = parseVersion(version1);
|
||||||
|
int[] v2Parts = parseVersion(version2);
|
||||||
|
|
||||||
|
int length = Math.max(v1Parts.length, v2Parts.length);
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
int part1 = i < v1Parts.length ? v1Parts[i] : 0;
|
||||||
|
int part2 = i < v2Parts.length ? v2Parts[i] : 0;
|
||||||
|
if (part1 != part2) {
|
||||||
|
return Integer.compare(part1, part2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0; // Versions are equal
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse a version string into an array of integers
|
||||||
|
* @param version The version string to parse
|
||||||
|
* Follows the format major.minor.patch, patch can contain -extension
|
||||||
|
*/
|
||||||
|
private static int[] parseVersion(String version) {
|
||||||
|
String[] parts = version.split("\\.");
|
||||||
|
int[] numbers = new int[parts.length];
|
||||||
|
// Major
|
||||||
|
numbers[0] = Integer.parseInt(parts[0]);
|
||||||
|
|
||||||
|
// Minor
|
||||||
|
numbers[1] = Integer.parseInt(parts[1]);
|
||||||
|
|
||||||
|
// Patch can contain -extension
|
||||||
|
if (parts[2].contains("-")) {
|
||||||
|
String[] extensionParts = parts[2].split("-");
|
||||||
|
numbers[2] = Integer.parseInt(extensionParts[0]);
|
||||||
|
} else {
|
||||||
|
numbers[2] = Integer.parseInt(parts[2]);
|
||||||
|
}
|
||||||
|
return numbers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We'll take the max from native migrations and double-check if there's any extension migration
|
* We'll take the max from native migrations and double-check if there's any extension migration
|
||||||
* pending to be applied
|
* pending to be applied
|
||||||
@ -203,7 +243,8 @@ public class MigrationWorkflow {
|
|||||||
List<String> executedMigrations, List<MigrationFile> availableMigrations) {
|
List<String> executedMigrations, List<MigrationFile> availableMigrations) {
|
||||||
Stream<MigrationFile> availableNativeMigrations =
|
Stream<MigrationFile> availableNativeMigrations =
|
||||||
availableMigrations.stream().filter(migration -> !migration.isExtension);
|
availableMigrations.stream().filter(migration -> !migration.isExtension);
|
||||||
Optional<String> maxMigration = executedMigrations.stream().max(String::compareTo);
|
Optional<String> maxMigration =
|
||||||
|
executedMigrations.stream().max(MigrationWorkflow::compareVersions);
|
||||||
if (maxMigration.isPresent()) {
|
if (maxMigration.isPresent()) {
|
||||||
return availableNativeMigrations
|
return availableNativeMigrations
|
||||||
.filter(migration -> migration.biggerThan(maxMigration.get()))
|
.filter(migration -> migration.biggerThan(maxMigration.get()))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user