Merge pull request #12360 from thingsboard/fix/upgrade-from

Ignore version from tb_schema_settings when from_version property is specified
This commit is contained in:
Viacheslav Klimov 2024-12-30 17:41:41 +02:00 committed by GitHub
commit d9f37cd2f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View File

@ -96,8 +96,6 @@ public class ThingsboardInstallService {
public void performInstall() { public void performInstall() {
try { try {
if (isUpgrade) { if (isUpgrade) {
log.info("Starting ThingsBoard Upgrade from version {} ...", upgradeFromVersion);
if ("cassandra-latest-to-postgres".equals(upgradeFromVersion)) { if ("cassandra-latest-to-postgres".equals(upgradeFromVersion)) {
log.info("Migrating ThingsBoard latest timeseries data from cassandra to SQL database ..."); log.info("Migrating ThingsBoard latest timeseries data from cassandra to SQL database ...");
latestMigrateService.migrate(); latestMigrateService.migrate();

View File

@ -17,6 +17,8 @@ package org.thingsboard.server.service.install;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
@ -39,6 +41,9 @@ public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSetti
private final BuildProperties buildProperties; private final BuildProperties buildProperties;
private final JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
@Value("${install.upgrade.from_version:}")
private String upgradeFromVersion;
private String packageSchemaVersion; private String packageSchemaVersion;
private String schemaVersionFromDb; private String schemaVersionFromDb;
@ -102,6 +107,15 @@ public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSetti
@Override @Override
public String getDbSchemaVersion() { public String getDbSchemaVersion() {
if (schemaVersionFromDb == null) { if (schemaVersionFromDb == null) {
if (StringUtils.isNotBlank(upgradeFromVersion)) {
/*
* TODO - Remove after the release of 3.9.0:
* This a temporary workaround due to the issue that schema version in the
* tb_schema_settings was set as 3.6.4 during the install of 3.8.1.
* */
schemaVersionFromDb = upgradeFromVersion;
return schemaVersionFromDb;
}
Long version = getSchemaVersionFromDb(); Long version = getSchemaVersionFromDb();
if (version == null) { if (version == null) {
onSchemaSettingsError("Upgrade failed: the database schema version is missing."); onSchemaSettingsError("Upgrade failed: the database schema version is missing.");