Browse Source
Run only target-family LTS migrations
pull/15808/head
Viacheslav Klimov
3 months ago
Failed to extract signature
2 changed files with
24 additions and
1 deletions
-
application/src/main/java/org/thingsboard/server/service/install/lts/LtsMigrationService.java
-
application/src/test/java/org/thingsboard/server/service/install/lts/LtsMigrationServiceTest.java
|
|
@ -110,7 +110,15 @@ public class LtsMigrationService { |
|
|
return migrations.stream() |
|
|
return migrations.stream() |
|
|
.filter(migration -> { |
|
|
.filter(migration -> { |
|
|
LtsVersion version = LtsVersion.parse(migration.getVersion()); |
|
|
LtsVersion version = LtsVersion.parse(migration.getVersion()); |
|
|
return version.compareTo(from) > 0 && version.compareTo(to) <= 0; |
|
|
// Run only migrations whose family matches the target version. Older-family
|
|
|
|
|
|
// migrations (e.g. 4.2.x) ride onto newer-family branches (e.g. 4.3.x) via the
|
|
|
|
|
|
// release-merge cascade, but each branch's own family of migrations is
|
|
|
|
|
|
// self-contained (newer-family copies reproduce the older schema/data changes),
|
|
|
|
|
|
// so a cross-family upgrade is fully handled by the target-family migrations.
|
|
|
|
|
|
// Excluding the dormant older-family beans avoids double-processing.
|
|
|
|
|
|
return version.sameFamily(to) |
|
|
|
|
|
&& version.compareTo(from) > 0 |
|
|
|
|
|
&& version.compareTo(to) <= 0; |
|
|
}) |
|
|
}) |
|
|
.toList(); |
|
|
.toList(); |
|
|
} |
|
|
} |
|
|
|
|
|
@ -113,6 +113,21 @@ class LtsMigrationServiceTest { |
|
|
verify(schemaSettingsService).updateSchemaVersion("4.2.2.4"); |
|
|
verify(schemaSettingsService).updateSchemaVersion("4.2.2.4"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void skipsMigrationsOutsideTargetFamilyOnCrossFamilyUpgrade() { |
|
|
|
|
|
List<String> applied = new ArrayList<>(); |
|
|
|
|
|
// 4.2.2.3 is carried onto a 4.3 branch by the release-merge cascade but must stay dormant:
|
|
|
|
|
|
// a cross-family 4.2 -> 4.3 upgrade is handled entirely by the 4.3-family migrations.
|
|
|
|
|
|
LtsMigrationService service = service(List.of( |
|
|
|
|
|
migration("4.2.2.3", applied), |
|
|
|
|
|
migration("4.3.1.2", applied), |
|
|
|
|
|
migration("4.3.1.3", applied))); |
|
|
|
|
|
|
|
|
|
|
|
service.runDataMigrations("4.2.2.2", "4.3.1.3"); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("4.3.1.2", "4.3.1.3"), applied); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
void reRunAtCurrentVersionIsNoOp() throws Exception { |
|
|
void reRunAtCurrentVersionIsNoOp() throws Exception { |
|
|
List<String> applied = new ArrayList<>(); |
|
|
List<String> applied = new ArrayList<>(); |
|
|
|