diff --git a/application/pom.xml b/application/pom.xml
index 05096269a8..1dcafd6e9c 100644
--- a/application/pom.xml
+++ b/application/pom.xml
@@ -10,7 +10,7 @@
4.0.0org.thingsboard
- 4.4.0.1-SNAPSHOT
+ 4.4.1-SNAPSHOTthingsboardapplication
diff --git a/application/src/main/data/upgrade/basic/schema_update.sql b/application/src/main/data/upgrade/basic/schema_update.sql
deleted file mode 100644
index bb5bf9075a..0000000000
--- a/application/src/main/data/upgrade/basic/schema_update.sql
+++ /dev/null
@@ -1,10 +0,0 @@
---
--- SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
--- SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
--- SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
---
-
--- Intentionally empty. The offline upgrade path is now fully bean-driven: every schema/data change lives in
--- an LtsMigration bean and its data/upgrade/lts//schema_update.sql (4.4 baseline DDL is in
--- V4_4_0_0Migration / lts/4.4.0.0/schema_update.sql). This file is kept present only so loadSql does not fail.
-
diff --git a/application/src/main/data/upgrade/lts/4.3.1.4/schema_update.sql b/application/src/main/data/upgrade/lts/4.3.1.4/schema_update.sql
index 7478f25bdf..80d0654fcc 100644
--- a/application/src/main/data/upgrade/lts/4.3.1.4/schema_update.sql
+++ b/application/src/main/data/upgrade/lts/4.3.1.4/schema_update.sql
@@ -16,7 +16,7 @@ ALTER TABLE alarm_comment DROP CONSTRAINT IF EXISTS fk_alarm_comment_alarm_id;
-- change (nullable, no default), so the ACCESS EXCLUSIVE lock it takes is released as soon as this
-- migration transaction commits.
--
--- The originator_id backfill for pre-existing rows is intentionally NOT done here. LtsMigrationService runs
+-- The originator_id backfill for pre-existing rows is intentionally NOT done here. MigrationService runs
-- this whole file inside a single transaction, so an in-line UPDATE would hold the ADD COLUMN's
-- ACCESS EXCLUSIVE lock for the entire backfill -- blocking all reads and writes on entity_alarm while the
-- no-downtime patch path (SystemPatchApplier) runs it on a serving node. Instead the backfill runs after
diff --git a/application/src/main/data/upgrade/lts/4.4.0.0/schema_update.sql b/application/src/main/data/upgrade/lts/4.4.0.0/schema_update.sql
index 4f84c6e011..9da79c3bad 100644
--- a/application/src/main/data/upgrade/lts/4.4.0.0/schema_update.sql
+++ b/application/src/main/data/upgrade/lts/4.4.0.0/schema_update.sql
@@ -14,9 +14,8 @@ ALTER TABLE rule_chain ADD COLUMN IF NOT EXISTS notes varchar(1000000);
-- RULE CHAIN NOTES MIGRATION END
--- PE-only 4.4 baseline DDL below (carried over from basic/schema_update.sql; these columns/index have no
--- owning bean of their own). report.* live on the PE-only report table; job.customer_id is a PE column on the
--- shared job table.
+-- PE-only 4.4 baseline DDL below (these columns/index have no owning bean of their own). report.* live on
+-- the PE-only report table; job.customer_id is a PE column on the shared job table.
-- REPORT PUBLIC LINK ADDITION START
diff --git a/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java b/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java
index bf9b2d41d7..07d14417bd 100644
--- a/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java
+++ b/application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java
@@ -114,7 +114,7 @@ public class ThingsboardInstallService {
entityDatabaseSchemaService.createOrUpdateViewsAndFunctions();
entityDatabaseSchemaService.createOrUpdateDeviceInfoView(persistToTelemetry);
} else {
- // TODO DON'T FORGET to update SUPPORTED_VERSIONS_FOR_UPGRADE and MIN_CE_VERSION_FOR_UPGRADE in DefaultDatabaseSchemaSettingsService
+ // TODO DON'T FORGET to update SUPPORTED_FAMILIES_FOR_UPGRADE and MIN_CE_VERSION_FOR_UPGRADE in DefaultDatabaseSchemaSettingsService
databaseSchemaVersionService.validateSchemaSettings();
// The database's own product marker selects the branch, so a CE database can never be taken
// down the PE path by a missing flag. --fromVersion=CE is still accepted, and now a no-op.
@@ -131,7 +131,7 @@ public class ThingsboardInstallService {
}
cacheCleanupService.clearCache();
if (updateFromCE) {
- // The LTS chain references PE-only tables and runs each of its files as a single transaction,
+ // The migration chain references PE-only tables and runs each of its files as a single transaction,
// so a converted CE database must get those tables before the chain rather than after it.
entityDatabaseSchemaService.createDatabaseSchema(false);
}
diff --git a/application/src/main/java/org/thingsboard/server/service/install/DatabaseSchemaSettingsService.java b/application/src/main/java/org/thingsboard/server/service/install/DatabaseSchemaSettingsService.java
index 5d4a09d9a2..dbfb1d17cd 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/DatabaseSchemaSettingsService.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/DatabaseSchemaSettingsService.java
@@ -9,7 +9,7 @@ public interface DatabaseSchemaSettingsService {
/**
* Whether the operator forced this offline upgrade past the version check (SKIP_SCHEMA_VERSION_CHECK). Besides
- * suppressing the validation errors, it makes the LTS migration selection inclusive of the stored version, so a
+ * suppressing the validation errors, it makes the migration selection inclusive of the stored version, so a
* database already at the package version re-runs that version's own migration instead of selecting nothing.
*/
boolean isForcedReUpgrade();
diff --git a/application/src/main/java/org/thingsboard/server/service/install/DefaultDatabaseSchemaSettingsService.java b/application/src/main/java/org/thingsboard/server/service/install/DefaultDatabaseSchemaSettingsService.java
index 496d9296a8..35fb27aed7 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/DefaultDatabaseSchemaSettingsService.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/DefaultDatabaseSchemaSettingsService.java
@@ -7,27 +7,24 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
-import org.thingsboard.server.service.install.lts.LtsVersion;
+import org.thingsboard.server.service.install.lts.Version;
import org.thingsboard.server.service.install.update.DefaultDataUpdateService;
-import java.util.Map;
+import java.util.List;
@Service
@Slf4j
@RequiredArgsConstructor
public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSettingsService {
- // map of versions from which the upgrade to the current version is possible
- // key - supported version prefix, value - display name
- private static final Map SUPPORTED_VERSIONS_FOR_UPGRADE = Map.of(
- "4.3.0", "4.3.0.x",
- "4.3.1", "4.3.1.x"
- );
+ // LTS families (major.minor) from which the offline upgrade to the current version is possible. A newer version
+ // within the package's own family needs no offline upgrade: SystemPatchApplier applies it on startup.
+ private static final List SUPPORTED_FAMILIES_FOR_UPGRADE = List.of(Version.parse("4.3"));
private static final String CE_PRODUCT = "CE";
// The first CE version that converts to PE: the one that ships the community grant. Anything older takes the
// cheap CE-to-CE patch upgrade first. 4.3 stays supported, so later 4.3.1.x releases convert as well.
- private static final LtsVersion MIN_CE_VERSION_FOR_UPGRADE = LtsVersion.parse("4.3.1.4");
+ private static final Version MIN_CE_VERSION_FOR_UPGRADE = Version.parse("4.3.1.6");
private final ProjectInfo projectInfo;
private final JdbcTemplate jdbcTemplate;
@@ -37,8 +34,8 @@ public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSetti
@Override
public void validateSchemaSettings() {
- // The flag also drops the CE floor below, and that is what it costs: the 4.3.1.4 minimum is
- // what keeps a CE source above 4.2.2.3, and so keeps LtsMigrationService.select() from ever returning
+ // The flag also drops the CE floor below, and that is what it costs: the CE minimum is
+ // what keeps a CE source above 4.2.2.3, and so keeps MigrationService.select() from ever returning
// the V4_2_2_3 <-> V4_3_1_3 reproduction-duplicate pair its own invariant forbids selecting together.
// Forcing an older CE database through without --fromVersion reopens that pair.
if (isForcedReUpgrade()) {
@@ -48,7 +45,7 @@ public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSetti
String dbSchemaVersion = getDbSchemaVersion();
if (isUpgradeFromCe()) {
- LtsVersion ceVersion = LtsVersion.parse(dbSchemaVersion);
+ Version ceVersion = Version.parse(dbSchemaVersion);
if (ceVersion.compareTo(MIN_CE_VERSION_FOR_UPGRADE) < 0) {
onSchemaSettingsError(String.format("Upgrade failed: transitioning from CE to PE requires the database to be at version '%s' or newer, but it is at '%s'. " +
"Please upgrade ThingsBoard CE to %s first.",
@@ -56,7 +53,7 @@ public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSetti
}
// Without this the migration chain would select nothing and the PE schema would be created on top of a
// newer CE database, silently.
- if (ceVersion.compareTo(LtsVersion.parse(getPackageSchemaVersion())) > 0) {
+ if (ceVersion.compareTo(Version.parse(getPackageSchemaVersion())) > 0) {
onSchemaSettingsError(String.format("Upgrade failed: the database is at CE version '%s', which is newer than this ThingsBoard PE package ('%s'). " +
"Please use a PE package of version '%s' or newer.",
dbSchemaVersion, getPackageSchemaVersion(), dbSchemaVersion));
@@ -66,10 +63,16 @@ public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSetti
onSchemaSettingsError("Upgrade failed: database already upgraded to current version. You can set SKIP_SCHEMA_VERSION_CHECK to 'true' if force re-upgrade needed.");
}
- if (SUPPORTED_VERSIONS_FOR_UPGRADE.keySet().stream().noneMatch(dbSchemaVersion::startsWith)) {
+ Version dbVersion = Version.parse(dbSchemaVersion);
+ Version packageVersion = Version.parse(getPackageSchemaVersion());
+ if (dbVersion.sameFamily(packageVersion) && dbVersion.compareTo(packageVersion) < 0) {
+ onSchemaSettingsError(String.format("Upgrade failed: database version '%s' is in the same LTS family as this package ('%s'). " +
+ "No upgrade is needed: the update is applied automatically when ThingsBoard starts.",
+ dbSchemaVersion, getPackageSchemaVersion()));
+ }
+ if (SUPPORTED_FAMILIES_FOR_UPGRADE.stream().noneMatch(dbVersion::sameFamily)) {
onSchemaSettingsError(String.format("Upgrade failed: database version '%s' is not supported for upgrade. Supported versions are: %s.",
- dbSchemaVersion, SUPPORTED_VERSIONS_FOR_UPGRADE.values()
- ));
+ dbSchemaVersion, SUPPORTED_FAMILIES_FOR_UPGRADE.stream().map(f -> f.major() + "." + f.minor() + ".x").toList()));
}
}
}
@@ -159,7 +162,7 @@ public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSetti
}
private long toDbVersion(String version) {
- LtsVersion v = LtsVersion.parse(version);
+ Version v = Version.parse(version);
return v.major() * 1_000_000_000L + v.minor() * 1_000_000L + v.maintenance() * 1000L + v.patch();
}
@@ -169,7 +172,7 @@ public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSetti
}
private String normalizeVersion(String version) {
- return LtsVersion.parse(version).toString();
+ return Version.parse(version).toString();
}
}
diff --git a/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java b/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java
index b7a75e407c..12e0f624a2 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java
@@ -11,7 +11,7 @@ import org.springframework.jdbc.core.StatementCallback;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
-import org.thingsboard.server.service.install.lts.LtsMigrationService;
+import org.thingsboard.server.service.install.lts.MigrationService;
import java.io.IOException;
import java.io.UncheckedIOException;
@@ -32,18 +32,18 @@ public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService
private final JdbcTemplate jdbcTemplate;
private final TransactionTemplate transactionTemplate;
private final DatabaseSchemaSettingsService schemaSettingsService;
- private final LtsMigrationService ltsMigrationService;
+ private final MigrationService migrationService;
public SqlDatabaseUpgradeService(InstallScripts installScripts, JdbcTemplate jdbcTemplate,
PlatformTransactionManager transactionManager,
DatabaseSchemaSettingsService schemaSettingsService,
- LtsMigrationService ltsMigrationService) {
+ MigrationService migrationService) {
this.installScripts = installScripts;
this.jdbcTemplate = jdbcTemplate;
this.transactionTemplate = new TransactionTemplate(transactionManager);
this.transactionTemplate.setTimeout((int) TimeUnit.MINUTES.toSeconds(120));
this.schemaSettingsService = schemaSettingsService;
- this.ltsMigrationService = ltsMigrationService;
+ this.migrationService = migrationService;
}
@Override
@@ -51,12 +51,11 @@ public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService
log.info("Updating schema...");
if (fromCe) {
// The delta is not confined to the version the database is already at - it also carries package-version
- // DDL that the LTS chain below adds again (the job.customer_id and tb_cluster columns, for instance).
+ // DDL that the migration chain below adds again (the job.customer_id and tb_cluster columns, for instance).
// Running it first is safe because every statement in it is repeat-safe, not because it is version-scoped.
loadSql(getSchemaUpdateFile("pe"));
}
- loadSql(getSchemaUpdateFile("basic"));
- ltsMigrationService.runSchemaMigrations(schemaSettingsService.getDbSchemaVersion(), schemaSettingsService.getPackageSchemaVersion(),
+ migrationService.runSchemaMigrations(schemaSettingsService.getDbSchemaVersion(), schemaSettingsService.getPackageSchemaVersion(),
schemaSettingsService.isForcedReUpgrade());
log.info("Schema updated.");
}
diff --git a/application/src/main/java/org/thingsboard/server/service/install/TbClusterSchema.java b/application/src/main/java/org/thingsboard/server/service/install/TbClusterSchema.java
index d07263af62..c9118894e7 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/TbClusterSchema.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/TbClusterSchema.java
@@ -4,7 +4,7 @@ package org.thingsboard.server.service.install;
/**
* The statements that reach {@code tb_cluster} from Java. The DDL is a hand-kept copy of the block in
- * {@code schema-entities.sql}; {@code LtsMigrationIntegrationTest} pins the copies against it.
+ * {@code schema-entities.sql}; {@code MigrationIntegrationTest} pins the copies against it.
*/
public final class TbClusterSchema {
diff --git a/application/src/main/java/org/thingsboard/server/service/install/lts/LtsMigration.java b/application/src/main/java/org/thingsboard/server/service/install/lts/Migration.java
similarity index 80%
rename from application/src/main/java/org/thingsboard/server/service/install/lts/LtsMigration.java
rename to application/src/main/java/org/thingsboard/server/service/install/lts/Migration.java
index 85f1b95b3d..9c60ab7d74 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/lts/LtsMigration.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/lts/Migration.java
@@ -4,12 +4,12 @@
package org.thingsboard.server.service.install.lts;
/**
- * One LTS migration, keyed by the version it ships in (e.g. "4.2.2.3").
+ * One migration, keyed by the version it ships in (e.g. "4.2.2.3").
* The runner runs the version's data/upgrade/lts/<version>/schema_update.sql by convention
* (if present), then calls {@link #apply()} for any programmatic work beyond SQL.
* Most migrations are SQL-only and only override {@link #getVersion()}.
*
- * Ordering caveat for a multi-version run (see {@link LtsMigrationService#applyMigrations}): on the no-downtime path
+ * Ordering caveat for a multi-version run (see {@link MigrationService#applyMigrations}): on the no-downtime path
* every migration's schema_update.sql + {@link #apply()} runs, in version order, BEFORE any migration's
* {@link #applyAfterCommit()}. So migration N+1's schema/apply executes ahead of migration N's backfill. A migration
* must therefore not depend, in its schema_update.sql or {@link #apply()}, on the completed result of an earlier
@@ -20,13 +20,13 @@ package org.thingsboard.server.service.install.lts;
* {@link #applyAfterCommit()} must therefore tolerate the schema changes of every later migration in the same run --
* equivalently, later DDL must not drop, rename, or retype anything an earlier migration's backfill reads or writes.
*/
-public interface LtsMigration {
+public interface Migration {
String getVersion();
/**
* Programmatic data migration that runs in the SAME transaction as the version's schema_update.sql
- * (see {@link LtsMigrationService#applyMigrations}). Use for work that must be atomic with the schema
+ * (see {@link MigrationService#applyMigrations}). Use for work that must be atomic with the schema
* change. Do NOT put heavy table rewrites here: on the no-downtime path the schema_update.sql DDL holds
* its locks until this transaction commits, so a long apply() keeps those locks held while the node serves.
*
@@ -38,13 +38,13 @@ public interface LtsMigration {
/**
* Programmatic data migration that runs AFTER the version's schema transaction has committed, outside any
- * transaction (see {@link LtsMigrationService#applyMigrations} and {@link LtsMigrationService#runDataMigrations}).
+ * transaction (see {@link MigrationService#applyMigrations} and {@link MigrationService#runDataMigrations}).
* Use for heavy or long-running data backfills that must not extend the lifetime of the schema-change locks:
* the implementation is responsible for chunking the work into its own small, self-committing transactions so
* it only ever holds row-level locks and never blocks concurrent readers/writers.
*
- * Must be idempotent and resumable: {@link LtsMigrationService#applyMigrations} does not record the version
- * itself, and the caller records it (see {@link LtsMigrationService#recordVersions}) only once whatever it
+ * Must be idempotent and resumable: {@link MigrationService#applyMigrations} does not record the version
+ * itself, and the caller records it (see {@link MigrationService#recordVersions}) only once whatever it
* needs after this method returns has also succeeded. A crash, or that later failure, before the version is
* recorded selects the migration again on the next startup and runs this method again from the start -- it
* must skip already-migrated rows rather than redo or double-count them.
diff --git a/application/src/main/java/org/thingsboard/server/service/install/lts/LtsMigrationService.java b/application/src/main/java/org/thingsboard/server/service/install/lts/MigrationService.java
similarity index 81%
rename from application/src/main/java/org/thingsboard/server/service/install/lts/LtsMigrationService.java
rename to application/src/main/java/org/thingsboard/server/service/install/lts/MigrationService.java
index bfc045457a..b4f3908dec 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/lts/LtsMigrationService.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/lts/MigrationService.java
@@ -24,10 +24,10 @@ import java.util.List;
import java.util.Set;
/**
- * Applies {@link LtsMigration} beans (in version order) for an LTS upgrade. Each migration has up to four idempotent
+ * Applies {@link Migration} beans (in version order) for an upgrade. Each migration has up to four idempotent
* parts: (1) its {@code schema_update.sql} DDL, run via {@link #executeSchemaSql} (absent file = no-op); (2)
- * {@link LtsMigration#apply()}, schema-coupled changes that must be atomic with the DDL; (3)
- * {@link LtsMigration#applyAfterCommit()}, the heavy backfill, run outside the DDL transaction and self-committing in
+ * {@link Migration#apply()}, schema-coupled changes that must be atomic with the DDL; (3)
+ * {@link Migration#applyAfterCommit()}, the heavy backfill, run outside the DDL transaction and self-committing in
* chunks; and (4) recording the version, which callers must delay until (2) and (3) -- and anything else they
* interpose -- have succeeded (see {@link #recordVersions}).
*
@@ -42,7 +42,7 @@ import java.util.Set;
*
Offline major upgrade -- runs in the install/upgrade process (node not serving), split across that
* process's schema and data phases: {@link #runSchemaMigrations} (DDL only) runs with the rest of the schema
* upgrade, then {@link #runDataMigrations} (apply() + backfill) runs later, after the install flow has created the
- * new tables, views/functions and indexes the data migrations may depend on. Neither records the LTS version; the
+ * new tables, views/functions and indexes the data migrations may depend on. Neither records the migration version; the
* offline upgrade flow tracks the package version itself.
*
*
@@ -56,12 +56,12 @@ import java.util.Set;
@Slf4j
@Component
@TbCoreComponent
-public class LtsMigrationService {
+public class MigrationService {
private static final String SCHEMA_UPDATE_SQL = "schema_update.sql";
/** A migration paired with its parsed version, so the version is parsed exactly once per bean. */
- private record VersionedMigration(LtsVersion version, LtsMigration migration) {}
+ private record VersionedMigration(Version version, Migration migration) {}
private final JdbcTemplate jdbcTemplate;
private final InstallScripts installScripts;
@@ -69,27 +69,27 @@ public class LtsMigrationService {
private final TransactionTemplate transactionTemplate;
private final List migrations;
- public LtsMigrationService(JdbcTemplate jdbcTemplate,
- InstallScripts installScripts,
- DatabaseSchemaSettingsService schemaSettingsService,
- PlatformTransactionManager transactionManager,
- List migrations) {
+ public MigrationService(JdbcTemplate jdbcTemplate,
+ InstallScripts installScripts,
+ DatabaseSchemaSettingsService schemaSettingsService,
+ PlatformTransactionManager transactionManager,
+ List migrations) {
this.jdbcTemplate = jdbcTemplate;
this.installScripts = installScripts;
this.schemaSettingsService = schemaSettingsService;
this.transactionTemplate = new TransactionTemplate(transactionManager);
this.migrations = validateAndSort(migrations);
- log.info("Discovered {} LTS migration(s): {}", this.migrations.size(),
+ log.info("Discovered {} migration(s): {}", this.migrations.size(),
this.migrations.stream().map(versionedMigration -> versionedMigration.migration().getVersion()).toList());
}
- private static List validateAndSort(List migrations) {
+ private static List validateAndSort(List migrations) {
Set seen = new HashSet<>();
List versioned = new ArrayList<>();
- for (LtsMigration migration : migrations) {
- LtsVersion version = LtsVersion.parse(migration.getVersion()); // fail loud on unparseable version
+ for (Migration migration : migrations) {
+ Version version = Version.parse(migration.getVersion()); // fail loud on unparseable version
if (!seen.add(migration.getVersion())) {
- throw new IllegalStateException("Duplicate LTS migration version: " + migration.getVersion());
+ throw new IllegalStateException("Duplicate migration version: " + migration.getVersion());
}
versioned.add(new VersionedMigration(version, migration));
}
@@ -110,17 +110,17 @@ public class LtsMigrationService {
public List applyMigrations(String fromVersion, String toVersion, boolean forcedRun, Runnable afterSchemaPhase) {
List selected = select(fromVersion, toVersion, forcedRun);
for (VersionedMigration versionedMigration : selected) {
- LtsMigration migration = versionedMigration.migration();
+ Migration migration = versionedMigration.migration();
transactionTemplate.executeWithoutResult(status -> {
executeSchemaSql(migration.getVersion());
migration.apply();
});
- log.info("Applied LTS schema update {}", migration.getVersion());
+ log.info("Applied schema update {}", migration.getVersion());
}
afterSchemaPhase.run();
List appliedVersions = new ArrayList<>();
for (VersionedMigration versionedMigration : selected) {
- LtsMigration migration = versionedMigration.migration();
+ Migration migration = versionedMigration.migration();
migration.applyAfterCommit(); // outside the schema transaction (see class doc)
appliedVersions.add(migration.getVersion());
}
@@ -130,12 +130,12 @@ public class LtsMigrationService {
/**
* Records the versions {@link #applyMigrations} returned, once the caller's own post-schema work has succeeded.
* Stamped together rather than one per backfill, so a later failure re-runs the earlier migrations' backfills on
- * the next startup - which {@link LtsMigration#applyAfterCommit} is required to tolerate.
+ * the next startup - which {@link Migration#applyAfterCommit} is required to tolerate.
*/
public void recordVersions(List versions) {
for (String version : versions) {
schemaSettingsService.updateSchemaVersion(version);
- log.info("Applied LTS migration {}", version);
+ log.info("Applied migration {}", version);
}
}
@@ -150,7 +150,7 @@ public class LtsMigrationService {
for (VersionedMigration versionedMigration : select(fromVersion, toVersion, forcedRun)) {
String version = versionedMigration.migration().getVersion();
transactionTemplate.executeWithoutResult(status -> executeSchemaSql(version));
- log.info("Applied LTS schema migration {}", version);
+ log.info("Applied schema migration {}", version);
}
}
@@ -163,16 +163,16 @@ public class LtsMigrationService {
*/
public void runDataMigrations(String fromVersion, String toVersion, boolean forcedRun) {
for (VersionedMigration versionedMigration : select(fromVersion, toVersion, forcedRun)) {
- LtsMigration migration = versionedMigration.migration();
+ Migration migration = versionedMigration.migration();
migration.apply();
migration.applyAfterCommit();
- log.info("Applied LTS data migration {}", migration.getVersion());
+ log.info("Applied data migration {}", migration.getVersion());
}
}
private List select(String fromVersion, String toVersion, boolean forcedRun) {
- LtsVersion from = LtsVersion.parse(fromVersion);
- LtsVersion to = LtsVersion.parse(toVersion);
+ Version from = Version.parse(fromVersion);
+ Version to = Version.parse(toVersion);
// Select every migration in the (from, to] range, regardless of family. On a cross-family offline
// upgrade (e.g. 4.3.x -> 4.4) this is what makes the real in-range older-family beans run: it picks the
// 4.3.1.x schema/data changes the source has not yet passed AND the new target-family beans, each exactly
@@ -184,8 +184,8 @@ public class LtsMigrationService {
// range. A reproduction-duplicate bean (one that re-does an older bean's work on a newer-family branch)
// must sit STRICTLY BELOW the minimum supported upgrade source, so it can never be selected together with
// the bean it duplicates. The pairs today are 4.2.2.3 <-> 4.3.1.3 and 4.2.2.4 <-> 4.3.1.4, and the
- // supported-source floor is 4.3.0.0 (SUPPORTED_VERSIONS_FOR_UPGRADE), well above both 4.2.2.x beans.
- // LtsMigrationServiceTest guards this.
+ // supported-source floor is 4.3.0.0 (SUPPORTED_FAMILIES_FOR_UPGRADE), well above both 4.2.2.x beans.
+ // MigrationServiceTest guards this.
//
// A forced run takes the closed [from, to] instead, so the source version's own migration re-runs rather than
// the range being empty -- see the class doc. It does not weaken that invariant in any new way: forcing
@@ -202,14 +202,14 @@ public class LtsMigrationService {
private void executeSchemaSql(String version) {
Path sqlFile = Paths.get(installScripts.getDataDir(), "upgrade", "lts", version, SCHEMA_UPDATE_SQL);
if (!Files.exists(sqlFile)) {
- log.trace("No LTS schema update file for version {} at {}", version, sqlFile);
+ log.trace("No schema update file for version {} at {}", version, sqlFile);
return;
}
try {
jdbcTemplate.execute(Files.readString(sqlFile));
- log.info("Applied LTS SQL schema update from {}", sqlFile);
+ log.info("Applied SQL schema update from {}", sqlFile);
} catch (IOException e) {
- throw new UncheckedIOException("Failed to read LTS schema update file: " + sqlFile, e);
+ throw new UncheckedIOException("Failed to read schema update file: " + sqlFile, e);
}
}
}
diff --git a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_2_2_3Migration.java b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_2_2_3Migration.java
index 4421b6ee41..ca46ee5e14 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_2_2_3Migration.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_2_2_3Migration.java
@@ -39,7 +39,7 @@ import java.util.stream.Stream;
@Component
@TbCoreComponent
@RequiredArgsConstructor
-public class V4_2_2_3Migration implements LtsMigration {
+public class V4_2_2_3Migration implements Migration {
// Match on the bundle ALIAS, not the JSON filename stem.
// The "industrial_widgets" bundle shipped in a misspelled file (industial_widgets.json),
diff --git a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_2Migration.java b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_2Migration.java
index 3593d99b64..7b50027d35 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_2Migration.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_2Migration.java
@@ -9,18 +9,18 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
/**
* Registration-only migration with no {@link #apply()} (no data migration), kept intentionally.
*
- * {@link LtsMigrationService} selects migrations from the injected {@link LtsMigration} beans, not from the
+ * {@link MigrationService} selects migrations from the injected {@link Migration} beans, not from the
* on-disk {@code data/upgrade/lts//} directories. So this bean is what makes the runner discover
* version {@code 4.3.1.2} and execute its {@code data/upgrade/lts/4.3.1.2/schema_update.sql} (which adds the
* 4.3.1.2 columns: {@code api_usage_state.ai}, {@code calculated_field.additional_info},
* {@code role.excluded_permissions}, {@code tb_user.external_id} plus the {@code tb_user_external_id_unq_key}
* constraint). A directory holding a {@code schema_update.sql} but lacking a matching bean would be silently skipped.
*
- * The dir/bean consistency (both ways) is guarded by a test in {@code LtsMigrationIntegrationTest}.
+ * The dir/bean consistency (both ways) is guarded by a test in {@code MigrationIntegrationTest}.
*/
@Component
@TbCoreComponent
-public class V4_3_1_2Migration implements LtsMigration {
+public class V4_3_1_2Migration implements Migration {
@Override
public String getVersion() {
diff --git a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_3Migration.java b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_3Migration.java
index 7cfa8c7332..2491a34c3b 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_3Migration.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_3Migration.java
@@ -42,7 +42,7 @@ import java.util.stream.Stream;
@Component
@TbCoreComponent
@RequiredArgsConstructor
-public class V4_3_1_3Migration implements LtsMigration {
+public class V4_3_1_3Migration implements Migration {
// Match on the bundle ALIAS, not the JSON filename stem.
// The "industrial_widgets" bundle shipped in a misspelled file (industial_widgets.json),
@@ -77,7 +77,7 @@ public class V4_3_1_3Migration implements LtsMigration {
@Override
public void applyAfterCommit() {
// Heavy per-tenant backfill: runs outside the schema transaction so it never holds the schema-change
- // locks while walking tenants (see LtsMigration#applyAfterCommit).
+ // locks while walking tenants (see Migration#applyAfterCommit).
migrateLegacySolutionTemplatesToIotHub();
}
diff --git a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_4Migration.java b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_4Migration.java
index 264b52f056..b796a1ecd7 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_4Migration.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_4Migration.java
@@ -17,7 +17,7 @@ import java.util.UUID;
/**
* Alarm sharding: drops the {@code alarm_comment -> alarm} cascade FK and adds {@code entity_alarm.originator_id}.
*
- * {@link LtsMigrationService} selects migrations from the injected {@link LtsMigration} beans, not from the on-disk
+ * {@link MigrationService} selects migrations from the injected {@link Migration} beans, not from the on-disk
* {@code data/upgrade/lts//} directories, so this bean is what makes the runner discover version
* {@code 4.3.1.4} and execute its {@code schema_update.sql} at all.
*
@@ -34,7 +34,7 @@ import java.util.UUID;
@Slf4j
@Component
@TbCoreComponent
-public class V4_3_1_4Migration implements LtsMigration {
+public class V4_3_1_4Migration implements Migration {
// entity_alarm is walked in keyset-paginated windows of this size, each in its own committed transaction, so
// the backfill only ever holds row-level locks on the current window and never blocks concurrent readers.
@@ -86,7 +86,7 @@ public class V4_3_1_4Migration implements LtsMigration {
/**
* Backfills entity_alarm.originator_id from the parent alarm for rows that predate the column added by this
- * version's schema_update.sql. Runs OUTSIDE the schema transaction (see {@link LtsMigration#applyAfterCommit})
+ * version's schema_update.sql. Runs OUTSIDE the schema transaction (see {@link Migration#applyAfterCommit})
* so the ADD COLUMN's ACCESS EXCLUSIVE lock is already released; each batch commits on its own and takes only
* a ROW EXCLUSIVE lock, so a serving node keeps reading and writing entity_alarm throughout.
*
diff --git a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_5Migration.java b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_5Migration.java
index 3642e23c41..87361ff51d 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_5Migration.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_5Migration.java
@@ -22,14 +22,14 @@ import java.util.Set;
import static org.thingsboard.server.dao.trendz.TrendzSyncService.TRENDZ_API_KEY_DESCRIPTION;
/**
- * LTS migration for version {@code 4.3.1.5}.
+ * Migration for version {@code 4.3.1.5}.
*
- * {@link LtsMigrationService} selects migrations from the injected {@link LtsMigration} beans, not from the on-disk
+ * {@link MigrationService} selects migrations from the injected {@link Migration} beans, not from the on-disk
* {@code data/upgrade/lts//} directories, so this bean is what makes the runner discover version
* {@code 4.3.1.5} at all.
*
* There is no {@code data/upgrade/lts/4.3.1.5/} directory: everything this version changes is programmatic, so the
- * version is listed in {@code SQL_LESS_ALLOWED} in {@code LtsMigrationIntegrationTest}, which otherwise fails a bean
+ * version is listed in {@code SQL_LESS_ALLOWED} in {@code MigrationIntegrationTest}, which otherwise fails a bean
* that has no matching directory. Should this version later need DDL, add the directory and drop that entry.
*
* Each thing this version migrates lives in its own private method called from {@link #apply()}, with the constants
@@ -39,7 +39,7 @@ import static org.thingsboard.server.dao.trendz.TrendzSyncService.TRENDZ_API_KEY
@Component
@TbCoreComponent
@RequiredArgsConstructor
-public class V4_3_1_5Migration implements LtsMigration {
+public class V4_3_1_5Migration implements Migration {
private final ApiKeyService apiKeyService;
@@ -50,7 +50,7 @@ public class V4_3_1_5Migration implements LtsMigration {
/**
* Runs in the same transaction as the version's schema SQL on the no-downtime path, and outside any transaction
- * on the offline path (see {@link LtsMigration#apply}). Every step below must therefore be light enough to sit in
+ * on the offline path (see {@link Migration#apply}). Every step below must therefore be light enough to sit in
* a schema transaction, and idempotent, since a crash before the version is recorded re-runs it.
*/
@Override
diff --git a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_6Migration.java b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_6Migration.java
index 1756033ef1..434394b586 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_6Migration.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_3_1_6Migration.java
@@ -20,7 +20,7 @@ import java.util.UUID;
@Component
@TbCoreComponent
@RequiredArgsConstructor
-public class V4_3_1_6Migration implements LtsMigration {
+public class V4_3_1_6Migration implements Migration {
private final JdbcTemplate jdbcTemplate;
diff --git a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_4_0_0Migration.java b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_4_0_0Migration.java
index a9e4b47e05..3341520dd1 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/lts/V4_4_0_0Migration.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/lts/V4_4_0_0Migration.java
@@ -19,30 +19,30 @@ import java.util.UUID;
* Registration-only migration with no {@link #apply()} (no data migration), plus an {@link #applyAfterCommit()}
* backfill that closes the pre-existing legacy stuck-RPC backlog.
*
- * {@link LtsMigrationService} selects migrations from the injected {@link LtsMigration} beans, not from the
+ * {@link MigrationService} selects migrations from the injected {@link Migration} beans, not from the
* on-disk {@code data/upgrade/lts//} directories. So this bean is what makes the runner discover
* version {@code 4.4.0.0} and execute its {@code data/upgrade/lts/4.4.0.0/schema_update.sql}, which -- among the
* other 4.4 changes -- adds the nullable {@code rpc.request_id} and {@code rpc.oneway} columns.
*
* The RPC change rides the {@code 4.4.0.0} slot rather than a 4.3/4.2-family one because it ships in 4.4 only.
* {@code 4.3.1.4} is already released (and, in PE, already carries the {@code entity_alarm.originator_id}
- * backfill), and {@link LtsVersion#isInRange} is exclusive at the lower bound -- so an installation already on
+ * backfill), and {@link Version#isInRange} is exclusive at the lower bound -- so an installation already on
* {@code 4.3.1.4} would never re-run that version. Every supported upgrade source ({@code 4.3.0.x},
* {@code 4.3.1.x}) is below {@code 4.4.0.0}, so all of them select this migration exactly once.
*
- * The dir/bean consistency (both ways) is guarded by a test in {@code LtsMigrationIntegrationTest}.
+ * The dir/bean consistency (both ways) is guarded by a test in {@code MigrationIntegrationTest}.
*
* {@link #applyAfterCommit()} closes rows left stuck by earlier server versions that predate {@code request_id}
* tracking: any {@code rpc} row with {@code request_id IS NULL} that is past its expiration and still sitting in
* {@code SENT} or {@code TIMEOUT}, or in {@code DELIVERED} for a two-way call (one-way {@code DELIVERED} is already terminal
* success), is force-closed to {@code EXPIRED} with a canned response. It walks the {@code rpc} table by primary
* key in keyset-paginated, self-committing batches so it never holds a long transaction or blocks concurrent
- * readers/writers; see the class-level backfill contract on {@link LtsMigration#applyAfterCommit()}.
+ * readers/writers; see the class-level backfill contract on {@link Migration#applyAfterCommit()}.
*/
@Slf4j
@Component
@TbCoreComponent
-public class V4_4_0_0Migration implements LtsMigration {
+public class V4_4_0_0Migration implements Migration {
// Same wording as DeviceActorMessageProcessor.LEGACY_UNTRACKED_MESSAGE, so a row closed by this one-time
// backfill reads identically to one closed live by the actor on reload.
diff --git a/application/src/main/java/org/thingsboard/server/service/install/lts/LtsVersion.java b/application/src/main/java/org/thingsboard/server/service/install/lts/Version.java
similarity index 80%
rename from application/src/main/java/org/thingsboard/server/service/install/lts/LtsVersion.java
rename to application/src/main/java/org/thingsboard/server/service/install/lts/Version.java
index a46c556095..7abf7c3420 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/lts/LtsVersion.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/lts/Version.java
@@ -3,9 +3,9 @@
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
package org.thingsboard.server.service.install.lts;
-public record LtsVersion(int major, int minor, int maintenance, int patch) implements Comparable {
+public record Version(int major, int minor, int maintenance, int patch) implements Comparable {
- public static LtsVersion parse(String version) {
+ public static Version parse(String version) {
if (version == null) {
throw new IllegalArgumentException("Version is null");
}
@@ -15,13 +15,13 @@ public record LtsVersion(int major, int minor, int maintenance, int patch) imple
int minor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0;
int maintenance = parts.length > 2 ? Integer.parseInt(parts[2]) : 0;
int patch = parts.length > 3 ? Integer.parseInt(parts[3]) : 0;
- return new LtsVersion(major, minor, maintenance, patch);
+ return new Version(major, minor, maintenance, patch);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid version: " + version, e);
}
}
- public boolean sameFamily(LtsVersion other) {
+ public boolean sameFamily(Version other) {
return major == other.major && minor == other.minor;
}
@@ -29,20 +29,20 @@ public record LtsVersion(int major, int minor, int maintenance, int patch) imple
* Half-open range check: {@code from < this <= to}. The lower bound is exclusive (a source already at
* {@code from} has applied that version) and the upper bound inclusive (the target version's own migration runs).
*/
- public boolean isInRange(LtsVersion from, LtsVersion to) {
+ public boolean isInRange(Version from, Version to) {
return compareTo(from) > 0 && compareTo(to) <= 0;
}
/**
* Closed range check: {@code from <= this <= to}. Only for a run an operator has forced past its version check,
- * where the source's own migration has to be re-run (see {@link LtsMigrationService}).
+ * where the source's own migration has to be re-run (see {@link MigrationService}).
*/
- public boolean isInClosedRange(LtsVersion from, LtsVersion to) {
+ public boolean isInClosedRange(Version from, Version to) {
return compareTo(from) >= 0 && compareTo(to) <= 0;
}
@Override
- public int compareTo(LtsVersion o) {
+ public int compareTo(Version o) {
int c = Integer.compare(major, o.major);
if (c != 0) {
return c;
diff --git a/application/src/main/java/org/thingsboard/server/service/install/update/DefaultDataUpdateService.java b/application/src/main/java/org/thingsboard/server/service/install/update/DefaultDataUpdateService.java
index e01e9b92b5..eb9ddb2c6a 100644
--- a/application/src/main/java/org/thingsboard/server/service/install/update/DefaultDataUpdateService.java
+++ b/application/src/main/java/org/thingsboard/server/service/install/update/DefaultDataUpdateService.java
@@ -55,7 +55,7 @@ import org.thingsboard.server.service.component.RuleNodeClassInfo;
import org.thingsboard.server.service.install.DatabaseSchemaSettingsService;
import org.thingsboard.server.service.install.DbUpgradeExecutorService;
import org.thingsboard.server.service.install.SystemDataLoaderService;
-import org.thingsboard.server.service.install.lts.LtsMigrationService;
+import org.thingsboard.server.service.install.lts.MigrationService;
import org.thingsboard.server.utils.TbNodeUpgradeUtils;
import java.lang.reflect.Field;
@@ -99,7 +99,7 @@ public class DefaultDataUpdateService implements DataUpdateService {
private final ComponentDiscoveryService componentDiscoveryService;
private final DbUpgradeExecutorService executorService;
private final DatabaseSchemaSettingsService schemaSettingsService;
- private final LtsMigrationService ltsMigrationService;
+ private final MigrationService migrationService;
@Override
public void updateData(boolean fromCe) throws Exception {
@@ -109,7 +109,7 @@ public class DefaultDataUpdateService implements DataUpdateService {
}
//TODO: should be cleaned after each release
backfillForExistingTenants();
- ltsMigrationService.runDataMigrations(schemaSettingsService.getDbSchemaVersion(), schemaSettingsService.getPackageSchemaVersion(),
+ migrationService.runDataMigrations(schemaSettingsService.getDbSchemaVersion(), schemaSettingsService.getPackageSchemaVersion(),
schemaSettingsService.isForcedReUpgrade());
log.info("Data updated.");
}
diff --git a/application/src/main/java/org/thingsboard/server/service/system/SystemPatchApplier.java b/application/src/main/java/org/thingsboard/server/service/system/SystemPatchApplier.java
index 50b2cd3b7b..bafaee6a3f 100644
--- a/application/src/main/java/org/thingsboard/server/service/system/SystemPatchApplier.java
+++ b/application/src/main/java/org/thingsboard/server/service/system/SystemPatchApplier.java
@@ -23,8 +23,8 @@ import org.thingsboard.server.dao.widget.WidgetsBundleService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.install.DatabaseSchemaSettingsService;
import org.thingsboard.server.service.install.InstallScripts;
-import org.thingsboard.server.service.install.lts.LtsMigrationService;
-import org.thingsboard.server.service.install.lts.LtsVersion;
+import org.thingsboard.server.service.install.lts.MigrationService;
+import org.thingsboard.server.service.install.lts.Version;
import org.thingsboard.server.service.install.update.DefaultDataUpdateService;
import java.io.IOException;
@@ -64,7 +64,7 @@ public class SystemPatchApplier {
private final WidgetTypeService widgetTypeService;
private final WidgetsBundleService widgetsBundleService;
private final ImageService imageService;
- private final LtsMigrationService ltsMigrationService;
+ private final MigrationService migrationService;
@PostConstruct
private void init() {
@@ -100,7 +100,7 @@ public class SystemPatchApplier {
// skipVersionCheck got us here with the database possibly already at the package version, where the
// default half-open selection would be empty: pass it on so that run still applies the stored version's
// own migration.
- List appliedVersions = ltsMigrationService.applyMigrations(dbVersion, packageVersion, skipVersionCheck, () -> {
+ List appliedVersions = migrationService.applyMigrations(dbVersion, packageVersion, skipVersionCheck, () -> {
// Between the schema and backfill phases: the schema phase may have added columns these definitions
// reference, and the refreshed definitions are then in effect for the whole backfill run. Each file
// is one jdbcTemplate.execute, so PostgreSQL runs it in a single implicit transaction and other
@@ -124,7 +124,7 @@ public class SystemPatchApplier {
int createdImages = createMissingSystemImages();
log.info("Created {} new system images", createdImages);
- ltsMigrationService.recordVersions(appliedVersions);
+ migrationService.recordVersions(appliedVersions);
schemaSettingsService.updateSchemaVersion();
log.info("System data patch update completed successfully");
@@ -139,11 +139,11 @@ public class SystemPatchApplier {
log.trace("Package version: {}, DB schema version: {}", packageVersion, dbVersion);
- LtsVersion packageVersionInfo;
- LtsVersion dbVersionInfo;
+ Version packageVersionInfo;
+ Version dbVersionInfo;
try {
- packageVersionInfo = LtsVersion.parse(packageVersion);
- dbVersionInfo = LtsVersion.parse(dbVersion);
+ packageVersionInfo = Version.parse(packageVersion);
+ dbVersionInfo = Version.parse(dbVersion);
} catch (IllegalArgumentException e) {
log.warn("Unable to parse versions. Package: {}, DB: {}", packageVersion, dbVersion);
return false;
diff --git a/application/src/test/java/org/thingsboard/server/install/ThingsboardInstallServiceTest.java b/application/src/test/java/org/thingsboard/server/install/ThingsboardInstallServiceTest.java
index 8591952462..d45fdf064d 100644
--- a/application/src/test/java/org/thingsboard/server/install/ThingsboardInstallServiceTest.java
+++ b/application/src/test/java/org/thingsboard/server/install/ThingsboardInstallServiceTest.java
@@ -134,7 +134,7 @@ class ThingsboardInstallServiceTest {
installService.performInstall();
- // The LTS files the chain applies reference PE-only tables and each of them runs as a single transaction,
+ // The migration files the chain applies reference PE-only tables and each of them runs as a single transaction,
// so a converted CE database must be given those tables before the chain runs rather than after it.
InOrder inOrder = inOrder(entityDatabaseSchemaService, databaseEntitiesUpgradeService, dataUpdateService);
inOrder.verify(entityDatabaseSchemaService).createDatabaseSchema(false);
diff --git a/application/src/test/java/org/thingsboard/server/service/install/DefaultDatabaseSchemaSettingsServiceTest.java b/application/src/test/java/org/thingsboard/server/service/install/DefaultDatabaseSchemaSettingsServiceTest.java
index 2fc1d1a7fd..d412245ea4 100644
--- a/application/src/test/java/org/thingsboard/server/service/install/DefaultDatabaseSchemaSettingsServiceTest.java
+++ b/application/src/test/java/org/thingsboard/server/service/install/DefaultDatabaseSchemaSettingsServiceTest.java
@@ -23,8 +23,8 @@ import static org.mockito.Mockito.when;
@MockitoSettings(strictness = Strictness.LENIENT)
class DefaultDatabaseSchemaSettingsServiceTest {
- private static final String PACKAGE_VERSION = "4.4.0";
- private static final long V_4_3_1_4 = 4_003_001_004L;
+ private static final String PACKAGE_VERSION = "4.4.1";
+ private static final long V_4_3_1_6 = 4_003_001_006L;
@Mock
private ProjectInfo projectInfo;
@@ -49,7 +49,7 @@ class DefaultDatabaseSchemaSettingsServiceTest {
@Test
void aCeDatabaseAtTheSupportedVersionIsAcceptedAndTakesTheConversionBranch() {
- givenSchemaSettings("CE", V_4_3_1_4);
+ givenSchemaSettings("CE", V_4_3_1_6);
service.validateSchemaSettings();
@@ -58,7 +58,7 @@ class DefaultDatabaseSchemaSettingsServiceTest {
@Test
void aPeDatabaseAtASupportedVersionIsAcceptedAndTakesThePlainUpgradeBranch() {
- givenSchemaSettings("PE", V_4_3_1_4);
+ givenSchemaSettings("PE", V_4_3_1_6);
service.validateSchemaSettings();
@@ -68,7 +68,7 @@ class DefaultDatabaseSchemaSettingsServiceTest {
@Test
void aCeDatabaseOnALaterPatchOfTheSupportedLineIsAlsoAccepted() {
// 4.3 keeps receiving patches, so the CE floor is a minimum rather than a single release.
- givenSchemaSettings("CE", 4_003_001_005L);
+ givenSchemaSettings("CE", 4_003_001_007L);
service.validateSchemaSettings();
@@ -77,7 +77,7 @@ class DefaultDatabaseSchemaSettingsServiceTest {
@Test
void aCeDatabaseNewerThanThePePackageIsRejected() {
- givenSchemaSettings("CE", 4_004_000_001L);
+ givenSchemaSettings("CE", 4_004_002_000L);
assertThatThrownBy(() -> service.validateSchemaSettings())
.hasMessageContaining("newer than this ThingsBoard PE package");
@@ -85,22 +85,53 @@ class DefaultDatabaseSchemaSettingsServiceTest {
@Test
void aCeDatabaseBelowTheSupportedVersionIsRejectedAtTheWall() {
- // 4.3.0.0: within the versions the PE branch accepts, but below the CE release that converts.
- givenSchemaSettings("CE", 4_003_000_000L);
+ // 4.3.1.5: within the versions the PE branch accepts, but below the CE release that converts.
+ givenSchemaSettings("CE", 4_003_001_005L);
assertThatThrownBy(() -> service.validateSchemaSettings())
.hasMessageContaining("transitioning from CE to PE")
- .hasMessageContaining("4.3.1.4");
+ .hasMessageContaining("4.3.1.6");
}
@Test
void aPeDatabaseAlreadyAtThePackageVersionIsRejected() {
- givenSchemaSettings("PE", 4_004_000_000L);
+ givenSchemaSettings("PE", 4_004_001_000L);
assertThatThrownBy(() -> service.validateSchemaSettings())
.hasMessageContaining("already upgraded to current version");
}
+ @Test
+ void aPeDatabaseAtTheFirstVersionOfTheSupportedFamilyIsAccepted() {
+ givenSchemaSettings("PE", 4_003_000_000L);
+
+ service.validateSchemaSettings();
+ }
+
+ @Test
+ void aPeDatabaseOnAFutureMaintenanceVersionOfTheSupportedFamilyIsAccepted() {
+ givenSchemaSettings("PE", 4_003_002_000L);
+
+ service.validateSchemaSettings();
+ }
+
+ @Test
+ void aPeDatabaseOnAnOlderVersionOfThePackageFamilyIsRejectedAsNotNeedingAnUpgrade() {
+ givenSchemaSettings("PE", 4_004_000_001L);
+
+ assertThatThrownBy(() -> service.validateSchemaSettings())
+ .hasMessageContaining("same LTS family")
+ .hasMessageContaining("applied automatically when ThingsBoard starts");
+ }
+
+ @Test
+ void aPeDatabaseOnANewerVersionOfThePackageFamilyIsRejected() {
+ givenSchemaSettings("PE", 4_004_002_000L);
+
+ assertThatThrownBy(() -> service.validateSchemaSettings())
+ .hasMessageContaining("is not supported for upgrade");
+ }
+
@Test
void aPeDatabaseAtAnUnsupportedVersionIsRejected() {
givenSchemaSettings("PE", 4_002_002_000L);
@@ -113,7 +144,7 @@ class DefaultDatabaseSchemaSettingsServiceTest {
void aDatabaseWithAnUnknownProductMarkerIsRejected() {
// Neither CE nor PE: unchecked, the marker would silently select the PE branch and the CE-to-PE
// conversion would be skipped on a database that needs it.
- givenSchemaSettings("TB", V_4_3_1_4);
+ givenSchemaSettings("TB", V_4_3_1_6);
assertThatThrownBy(() -> service.validateSchemaSettings())
.hasMessageContaining("unrecognized product");
@@ -121,7 +152,7 @@ class DefaultDatabaseSchemaSettingsServiceTest {
@Test
void aDatabaseWithoutAProductMarkerIsRejected() {
- givenSchemaSettings(null, V_4_3_1_4);
+ givenSchemaSettings(null, V_4_3_1_6);
assertThatThrownBy(() -> service.validateSchemaSettings())
.hasMessageContaining("unrecognized product");
@@ -131,7 +162,7 @@ class DefaultDatabaseSchemaSettingsServiceTest {
void anUnrecognizedProductMarkerIsRejectedByTheBranchSelectorItself() {
// The guard has to live where the branch is chosen: validateSchemaSettings() returns early when
// SKIP_SCHEMA_VERSION_CHECK is set, and the upgrade then asks isUpgradeFromCe() regardless.
- givenSchemaSettings("TB", V_4_3_1_4);
+ givenSchemaSettings("TB", V_4_3_1_6);
assertThatThrownBy(() -> service.isUpgradeFromCe())
.hasMessageContaining("unrecognized product");
@@ -139,7 +170,7 @@ class DefaultDatabaseSchemaSettingsServiceTest {
@Test
void aMissingProductMarkerIsRejectedByTheBranchSelectorItself() {
- givenSchemaSettings(null, V_4_3_1_4);
+ givenSchemaSettings(null, V_4_3_1_6);
assertThatThrownBy(() -> service.isUpgradeFromCe())
.hasMessageContaining("unrecognized product");
diff --git a/application/src/test/java/org/thingsboard/server/service/install/PeUpgradeAlarmShardingIntegrationTest.java b/application/src/test/java/org/thingsboard/server/service/install/PeUpgradeAlarmShardingIntegrationTest.java
index 3105391880..d13a14fb84 100644
--- a/application/src/test/java/org/thingsboard/server/service/install/PeUpgradeAlarmShardingIntegrationTest.java
+++ b/application/src/test/java/org/thingsboard/server/service/install/PeUpgradeAlarmShardingIntegrationTest.java
@@ -19,7 +19,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
- * CE-to-PE twin of the 4.3.1.4 alarm-sharding coverage in {@code LtsMigrationIntegrationTest}: the same schema
+ * CE-to-PE twin of the 4.3.1.4 alarm-sharding coverage in {@code MigrationIntegrationTest}: the same schema
* change (alarm_comment FK drop, entity_alarm.originator_id ADD COLUMN) plus the deliberately single-statement
* originator backfill live in upgrade/pe/schema_update.sql and are executed by no other test. The whole file is
* idempotent by design (SqlDatabaseUpgradeService sends it as one execute), so the test runs it verbatim — twice,
diff --git a/application/src/test/java/org/thingsboard/server/service/install/PeUpgradeChainIntegrationTest.java b/application/src/test/java/org/thingsboard/server/service/install/PeUpgradeChainIntegrationTest.java
index 526c7cdccd..131cb96444 100644
--- a/application/src/test/java/org/thingsboard/server/service/install/PeUpgradeChainIntegrationTest.java
+++ b/application/src/test/java/org/thingsboard/server/service/install/PeUpgradeChainIntegrationTest.java
@@ -35,7 +35,7 @@ import org.thingsboard.server.dao.tenant.TenantService;
import org.thingsboard.server.dao.user.UserService;
import org.thingsboard.server.dao.wl.WhiteLabelingService;
import org.thingsboard.server.service.component.ComponentDiscoveryService;
-import org.thingsboard.server.service.install.lts.LtsMigrationService;
+import org.thingsboard.server.service.install.lts.MigrationService;
import org.thingsboard.server.service.install.update.DefaultDataUpdateService;
import java.util.ArrayList;
@@ -55,7 +55,7 @@ import static org.mockito.Mockito.when;
/**
* Two parts of the offline upgrade driven against a real database: the CE-to-PE data conversion
* ({@code updateData(true)}) replayed the way a crashed conversion replays it, and a PE database stamped at a
- * pre-4.4 version taken to the package version by the real LTS chain ({@code upgradeDatabase(false)}), from the
+ * pre-4.4 version taken to the package version by the real migration chain ({@code upgradeDatabase(false)}), from the
* position the chain now runs from for both sources.
*
* What is not here is the CE schema fork, {@code upgradeDatabase(true)}. The fixture below builds CE-shaped
@@ -81,7 +81,7 @@ public class PeUpgradeChainIntegrationTest extends AbstractControllerTest {
private static final List COUNTED_TABLES = List.of(
"entity_group", "relation", "tenant", "customer", "tb_user", "device", "asset", "dashboard");
- // Columns added by the LTS files the chain selects. report is the PE-only table the whole ordering fix exists
+ // Columns added by the migration files the chain selects. report is the PE-only table the whole ordering fix exists
// for, so its two 4.4 columns are in the set even though report_info_view's SELECT r.* captures them.
private static final List V_4_3_1_2_COLUMNS = List.of(
new Column("calculated_field", "additional_info", "varchar"),
@@ -104,7 +104,7 @@ public class PeUpgradeChainIntegrationTest extends AbstractControllerTest {
@Autowired
private InstallScripts installScripts;
@Autowired
- private LtsMigrationService ltsMigrationService;
+ private MigrationService migrationService;
@Autowired
private PlatformTransactionManager transactionManager;
@@ -281,8 +281,8 @@ public class PeUpgradeChainIntegrationTest extends AbstractControllerTest {
/**
* The real conversion, wired to the real DAO services. Only the collaborators outside it are stood in for:
- * the two install-profile beans a test context does not have, and the LTS data phase, which
- * {@link org.thingsboard.server.service.install.lts.LtsMigrationIntegrationTest} owns.
+ * the two install-profile beans a test context does not have, and the migration data phase, which
+ * {@link org.thingsboard.server.service.install.lts.MigrationIntegrationTest} owns.
*/
private DefaultDataUpdateService ceDataUpdateService() {
return new DefaultDataUpdateService(tenantService, relationService, ruleChainService, integrationService,
@@ -290,7 +290,7 @@ public class PeUpgradeChainIntegrationTest extends AbstractControllerTest {
dashboardService, entityViewService, edgeService, agentProfileService,
mock(SystemDataLoaderService.class), mock(ComponentDiscoveryService.class),
inlineUpgradeExecutor(), schemaSettingsStubbedAt("4.3.1.4"),
- mock(LtsMigrationService.class));
+ mock(MigrationService.class));
}
/**
@@ -310,7 +310,7 @@ public class PeUpgradeChainIntegrationTest extends AbstractControllerTest {
/** The real schema upgrade, with only the version pair it is driven over stubbed. */
private SqlDatabaseUpgradeService upgradeService(String fromVersion) {
return new SqlDatabaseUpgradeService(installScripts, jdbcTemplate, transactionManager,
- schemaSettingsStubbedAt(fromVersion), ltsMigrationService);
+ schemaSettingsStubbedAt(fromVersion), migrationService);
}
private DatabaseSchemaSettingsService schemaSettingsStubbedAt(String dbVersion) {
diff --git a/application/src/test/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeServiceTest.java b/application/src/test/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeServiceTest.java
index 98e9ff24f9..4b79aa5c18 100644
--- a/application/src/test/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeServiceTest.java
+++ b/application/src/test/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeServiceTest.java
@@ -12,7 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.StatementCallback;
import org.springframework.transaction.PlatformTransactionManager;
-import org.thingsboard.server.service.install.lts.LtsMigrationService;
+import org.thingsboard.server.service.install.lts.MigrationService;
import java.io.IOException;
import java.nio.file.Files;
@@ -27,14 +27,13 @@ import static org.mockito.Mockito.when;
/**
* A converted CE database is at a CE version, not at the package version, so the CE-to-PE delta cannot be the whole
- * schema upgrade: the delta gives the database the PE shape of the version it is already at, and the LTS chain then
+ * schema upgrade: the delta gives the database the PE shape of the version it is already at, and the migration chain then
* has to take it the rest of the way exactly as it does for a PE source.
*/
@ExtendWith(MockitoExtension.class)
class SqlDatabaseUpgradeServiceTest {
private static final String PE_DELTA_SQL = "-- the CE to PE delta\n";
- private static final String BASIC_SQL = "-- the basic schema update\n";
private static final String DB_VERSION = "4.3.1.4";
private static final String PACKAGE_VERSION = "4.4.0.0";
@@ -47,7 +46,7 @@ class SqlDatabaseUpgradeServiceTest {
@Mock
private DatabaseSchemaSettingsService schemaSettingsService;
@Mock
- private LtsMigrationService ltsMigrationService;
+ private MigrationService migrationService;
@Mock
private Statement statement;
@@ -60,24 +59,22 @@ class SqlDatabaseUpgradeServiceTest {
@SuppressWarnings("unchecked")
void setUp() throws IOException {
writeSchemaUpdate("pe", PE_DELTA_SQL);
- writeSchemaUpdate("basic", BASIC_SQL);
when(installScripts.getDataDir()).thenReturn(dataDir.toString());
when(schemaSettingsService.getDbSchemaVersion()).thenReturn(DB_VERSION);
when(schemaSettingsService.getPackageSchemaVersion()).thenReturn(PACKAGE_VERSION);
// Run the callback the service passes, so the SQL it hands to the statement can be asserted on.
when(jdbcTemplate.execute(any(StatementCallback.class)))
.thenAnswer(invocation -> ((StatementCallback