[Minor] Automated Code cleanup: Class can be a record
This commit is contained in:
parent
877c02ede8
commit
d74ed6fb2d
|
@ -10,27 +10,21 @@ import li.strolch.utils.Version;
|
||||||
*
|
*
|
||||||
* @author Reto Breitenmoser <reto.breitenmoser@4trees.ch>
|
* @author Reto Breitenmoser <reto.breitenmoser@4trees.ch>
|
||||||
*/
|
*/
|
||||||
public class MigrationVersion {
|
public record MigrationVersion(Version dataVersion, Version codeVersion) {
|
||||||
|
|
||||||
private final Version dataVersion;
|
|
||||||
private final Version codeVersion;
|
|
||||||
|
|
||||||
public MigrationVersion(Version dataVersion, Version codeVersion) {
|
|
||||||
this.dataVersion = dataVersion;
|
|
||||||
this.codeVersion = codeVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the dataVersion
|
* @return the dataVersion
|
||||||
*/
|
*/
|
||||||
public Version getDataVersion() {
|
@Override
|
||||||
|
public Version dataVersion() {
|
||||||
return dataVersion;
|
return dataVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the codeVersion
|
* @return the codeVersion
|
||||||
*/
|
*/
|
||||||
public Version getCodeVersion() {
|
@Override
|
||||||
|
public Version codeVersion() {
|
||||||
return codeVersion;
|
return codeVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,8 +92,8 @@ public class Migrations {
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
logger.info("[" + realm + "] Performing all migrations after " + currentVersion);
|
logger.info("[" + realm + "] Performing all migrations after " + currentVersion);
|
||||||
|
|
||||||
Version nextPossibleCodeVersion = currentVersion.getCodeVersion().add(0, 0, 1);
|
Version nextPossibleCodeVersion = currentVersion.codeVersion().add(0, 0, 1);
|
||||||
Version nextPossibleDataVersion = currentVersion.getDataVersion().add(0, 0, 1);
|
Version nextPossibleDataVersion = currentVersion.dataVersion().add(0, 0, 1);
|
||||||
CodeMigration currentCodeMigration = new CodeMigration(realm, nextPossibleCodeVersion, null);
|
CodeMigration currentCodeMigration = new CodeMigration(realm, nextPossibleCodeVersion, null);
|
||||||
DataMigration currentDataMigration = new DataMigration(realm, nextPossibleDataVersion, null);
|
DataMigration currentDataMigration = new DataMigration(realm, nextPossibleDataVersion, null);
|
||||||
|
|
||||||
|
@ -170,16 +170,16 @@ public class Migrations {
|
||||||
SortedSet<CodeMigration> migrations = new TreeSet<>(Comparator.comparing(Migration::getVersion));
|
SortedSet<CodeMigration> migrations = new TreeSet<>(Comparator.comparing(Migration::getVersion));
|
||||||
migrations.addAll(listOfMigrations);
|
migrations.addAll(listOfMigrations);
|
||||||
|
|
||||||
Version nextVersion = currentVersion.getCodeVersion().add(0, 0, 1);
|
Version nextVersion = currentVersion.codeVersion().add(0, 0, 1);
|
||||||
CodeMigration nextMigration = new CodeMigration(realm, nextVersion);
|
CodeMigration nextMigration = new CodeMigration(realm, nextVersion);
|
||||||
|
|
||||||
SortedSet<CodeMigration> migrationsToRun = migrations.tailSet(nextMigration);
|
SortedSet<CodeMigration> migrationsToRun = migrations.tailSet(nextMigration);
|
||||||
for (CodeMigration migration : migrationsToRun) {
|
for (CodeMigration migration : migrationsToRun) {
|
||||||
DBC.INTERIM.assertEquals("Realms do not match!", realm, migration.getRealm());
|
DBC.INTERIM.assertEquals("Realms do not match!", realm, migration.getRealm());
|
||||||
Version migrateVersion = migration.getVersion();
|
Version migrateVersion = migration.getVersion();
|
||||||
boolean isLaterMigration = migrateVersion.compareTo(currentVersion.getCodeVersion()) > 0;
|
boolean isLaterMigration = migrateVersion.compareTo(currentVersion.codeVersion()) > 0;
|
||||||
DBC.INTERIM.assertTrue(
|
DBC.INTERIM.assertTrue(
|
||||||
"Current version " + currentVersion.getCodeVersion() + " is not before next " + migrateVersion,
|
"Current version " + currentVersion.codeVersion() + " is not before next " + migrateVersion,
|
||||||
isLaterMigration);
|
isLaterMigration);
|
||||||
|
|
||||||
String msg = "[{0}] Running code migration {1} {2}";
|
String msg = "[{0}] Running code migration {1} {2}";
|
||||||
|
@ -295,8 +295,8 @@ public class Migrations {
|
||||||
|
|
||||||
for (Entry<String, MigrationVersion> entry : currentVersions.entrySet()) {
|
for (Entry<String, MigrationVersion> entry : currentVersions.entrySet()) {
|
||||||
String realm = entry.getKey();
|
String realm = entry.getKey();
|
||||||
Version nextPossibleCodeVersion = entry.getValue().getCodeVersion().add(0, 0, 1);
|
Version nextPossibleCodeVersion = entry.getValue().codeVersion().add(0, 0, 1);
|
||||||
Version nextPossibleDataVersion = entry.getValue().getDataVersion().add(0, 0, 1);
|
Version nextPossibleDataVersion = entry.getValue().dataVersion().add(0, 0, 1);
|
||||||
CodeMigration currentCodeMigration = new CodeMigration(realm, nextPossibleCodeVersion, null);
|
CodeMigration currentCodeMigration = new CodeMigration(realm, nextPossibleCodeVersion, null);
|
||||||
DataMigration currentDataMigration = new DataMigration(realm, nextPossibleDataVersion, null);
|
DataMigration currentDataMigration = new DataMigration(realm, nextPossibleDataVersion, null);
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,8 @@ public class MigrationsTest {
|
||||||
MigrationsHandler migrationsHandler = runtimeMock.getContainer().getComponent(MigrationsHandler.class);
|
MigrationsHandler migrationsHandler = runtimeMock.getContainer().getComponent(MigrationsHandler.class);
|
||||||
Map<String, MigrationVersion> currentVersions = migrationsHandler.getCurrentVersions(certificate);
|
Map<String, MigrationVersion> currentVersions = migrationsHandler.getCurrentVersions(certificate);
|
||||||
String defRealm = StrolchConstants.DEFAULT_REALM;
|
String defRealm = StrolchConstants.DEFAULT_REALM;
|
||||||
assertEquals("1.1.1", currentVersions.get(defRealm).getDataVersion().toString());
|
assertEquals("1.1.1", currentVersions.get(defRealm).dataVersion().toString());
|
||||||
assertEquals("0.0.0", currentVersions.get("other").getCodeVersion().toString());
|
assertEquals("0.0.0", currentVersions.get("other").codeVersion().toString());
|
||||||
|
|
||||||
MapOfLists<String, Version> lastMigrations = migrationsHandler.getLastMigrations();
|
MapOfLists<String, Version> lastMigrations = migrationsHandler.getLastMigrations();
|
||||||
List<Version> expectedMigrations = Arrays
|
List<Version> expectedMigrations = Arrays
|
||||||
|
@ -85,8 +85,8 @@ public class MigrationsTest {
|
||||||
|
|
||||||
// assert new current version
|
// assert new current version
|
||||||
currentVersions = migrationsHandler.getCurrentVersions(certificate);
|
currentVersions = migrationsHandler.getCurrentVersions(certificate);
|
||||||
assertEquals("1.1.1", currentVersions.get(defRealm).getDataVersion().toString());
|
assertEquals("1.1.1", currentVersions.get(defRealm).dataVersion().toString());
|
||||||
assertEquals("0.0.0", currentVersions.get("other").getCodeVersion().toString());
|
assertEquals("0.0.0", currentVersions.get("other").codeVersion().toString());
|
||||||
|
|
||||||
MapOfLists<String, CodeMigration> codeMigrationsByRealm = new MapOfLists<>();
|
MapOfLists<String, CodeMigration> codeMigrationsByRealm = new MapOfLists<>();
|
||||||
// add migrations in wrong sequence - should be fixed by migration handler
|
// add migrations in wrong sequence - should be fixed by migration handler
|
||||||
|
@ -102,8 +102,8 @@ public class MigrationsTest {
|
||||||
|
|
||||||
// assert new current version
|
// assert new current version
|
||||||
currentVersions = migrationsHandler.getCurrentVersions(certificate);
|
currentVersions = migrationsHandler.getCurrentVersions(certificate);
|
||||||
assertEquals("1.2.0.a", currentVersions.get(defRealm).getCodeVersion().toString());
|
assertEquals("1.2.0.a", currentVersions.get(defRealm).codeVersion().toString());
|
||||||
assertEquals("0.0.0", currentVersions.get("other").getDataVersion().toString());
|
assertEquals("0.0.0", currentVersions.get("other").dataVersion().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MyMigration0 extends CodeMigration {
|
private static class MyMigration0 extends CodeMigration {
|
||||||
|
|
Loading…
Reference in New Issue