Browse Source

Improvements to the upgrade script

pull/7001/head
Andrii Shvaika 4 years ago
parent
commit
079c610ffc
  1. 6
      application/src/main/java/org/thingsboard/server/service/install/update/DefaultDataUpdateService.java
  2. 16
      dao/src/main/java/org/thingsboard/server/dao/sql/event/SqlEventCleanupRepository.java

6
application/src/main/java/org/thingsboard/server/service/install/update/DefaultDataUpdateService.java

@ -164,10 +164,12 @@ public class DefaultDataUpdateService implements DataUpdateService {
rateLimitsUpdater.updateEntities();
break;
case "3.4.0":
if (System.getProperty("TB_EVENTS_MIGRATION", "false").equalsIgnoreCase("true")) {
log.info("Updating data from version 3.3.4 to 3.4.0 ...");
String skipEventsMigration = System.getenv("TB_SKIP_EVENTS_MIGRATION");
if (skipEventsMigration == null || skipEventsMigration.equalsIgnoreCase("false")) {
log.info("Updating data from version 3.4.0 to 3.4.1 ...");
eventService.migrateEvents();
}
break;
default:
throw new RuntimeException("Unable to update data, unsupported fromVersion: " + fromVersion);
}

16
dao/src/main/java/org/thingsboard/server/dao/sql/event/SqlEventCleanupRepository.java

@ -54,6 +54,17 @@ public class SqlEventCleanupRepository extends JpaAbstractDaoListeningExecutorSe
public void migrateEvents(long regularEventTs, long debugEventTs) {
callMigrateFunction("migrate_regular_events", regularEventTs, partitionConfiguration.getRegularPartitionSizeInHours());
callMigrateFunction("migrate_debug_events", debugEventTs, partitionConfiguration.getDebugPartitionSizeInHours());
try (Connection connection = dataSource.getConnection();
PreparedStatement dropFunction1 = connection.prepareStatement("DROP PROCEDURE IF EXISTS migrate_regular_events");
PreparedStatement dropFunction2 = connection.prepareStatement("DROP PROCEDURE IF EXISTS migrate_debug_events");
PreparedStatement dropTable = connection.prepareStatement("DROP TABLE IF EXISTS event")) {
dropFunction1.execute();
dropFunction2.execute();
dropTable.execute();
} catch (SQLException e) {
log.error("SQLException occurred during drop of the `events` table", e);
throw new RuntimeException(e);
}
}
private void callMigrateFunction(String functionName, long startTs, int partitionSizeInHours) {
@ -63,7 +74,10 @@ public class SqlEventCleanupRepository extends JpaAbstractDaoListeningExecutorSe
stmt.setInt(2, partitionSizeInHours);
stmt.execute();
} catch (SQLException e) {
log.error("[{}] SQLException occurred during execution of {} with parameters {} and {}", functionName, startTs, partitionSizeInHours, e);
if (e.getMessage() == null || !e.getMessage().contains("relation \"event\" does not exist")) {
log.error("[{}] SQLException occurred during execution of {} with parameters {} and {}", functionName, startTs, partitionSizeInHours, e);
throw new RuntimeException(e);
}
}
}

Loading…
Cancel
Save