@ -21,17 +21,18 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service ;
import org.thingsboard.server.service.install.update.DefaultDataUpdateService ;
import java.util.List ;
import java.util.Map ;
@Service
@Slf4j
@RequiredArgsConstructor
public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSettingsService {
// This list should include all versions that are compatible for the upgrade in 4 digits format (like 4.2.0.0, etc.).
// The compatibility cycle usually breaks when we have some scripts written in Java that may not work after a new release.
// TODO: don't check the "patch" number, since upgrade is not required for patch releases
private static final List < String > SUPPORTED_VERSIONS_FOR_UPGRADE = List . of ( "4.3.0.0" ) ;
// map of versions from which the upgrade to the current version is possible
// key - supported version prefix, value - display name
private static final Map < String , String > SUPPORTED_VERSIONS_FOR_UPGRADE = Map . of (
"4.2.1" , "4.2.1.x"
) ;
private final ProjectInfo projectInfo ;
private final JdbcTemplate jdbcTemplate ;
@ -56,9 +57,9 @@ 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 . contains ( dbSchemaVersion ) ) {
if ( SUPPORTED_VERSIONS_FOR_UPGRADE . keySet ( ) . stream ( ) . noneMatch ( dbSchemaVersion : : startsWith ) ) {
onSchemaSettingsError ( String . format ( "Upgrade failed: database version '%s' is not supported for upgrade. Supported versions are: %s." ,
dbSchemaVersion , SUPPORTED_VERSIONS_FOR_UPGRADE
dbSchemaVersion , SUPPORTED_VERSIONS_FOR_UPGRADE . values ( )
) ) ;
}
}