Fix migrations
This commit is contained in:
@@ -35,8 +35,8 @@ public class MetricFilter implements Filter {
|
||||
double stopTime = System.nanoTime();
|
||||
double execTime = (stopTime - startTime) / 1000000000;
|
||||
// final int status = ((HttpServletResponse) response).getStatus();
|
||||
Double duration = Double.valueOf(execTime);
|
||||
metricService.updateCountTimeForService(req, duration);
|
||||
|
||||
metricService.updateCountTimeForService(req, execTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +136,8 @@ public class MigrationService {
|
||||
MigrationModelInterface migrationInstance = migrationClass.newInstance();
|
||||
migrationInstance.init(advancedDataSource, settingsController, settingsModel, droolsDataCompleting);
|
||||
migrationInstance.up();
|
||||
|
||||
advancedDataSource.getConnection().commit();
|
||||
}
|
||||
|
||||
public void updateLastMigrationIntoDB(AdvancedDataSource advancedDataSource, long lastMigraton) throws Exception {
|
||||
@@ -171,10 +173,14 @@ public class MigrationService {
|
||||
|
||||
private void migrateStatus(AdvancedDataSource advancedDataSource) throws Exception {
|
||||
final long lastMigrationNumber = getLastMigrationFromDB(advancedDataSource);
|
||||
final List<Long> alreadyExecutedMigrations = retrieveAllMigrationsStatus(advancedDataSource)
|
||||
.stream()
|
||||
.map(StbMigrationStatus::getMigrationCode)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final List<StbMigrationStatus> migrationStatusesToMigrate = allMigrationsList.stream()
|
||||
.map(x -> Long.parseLong(x.getSimpleName().replace("Migration_", "")))
|
||||
.filter(x -> x <= lastMigrationNumber)
|
||||
.filter(x -> x <= lastMigrationNumber && !alreadyExecutedMigrations.contains(x))
|
||||
.map(x -> {
|
||||
final StbMigrationStatus stbMigrationStatus = new StbMigrationStatus()
|
||||
.setMigrationCode(x)
|
||||
@@ -187,6 +193,8 @@ public class MigrationService {
|
||||
for (StbMigrationStatus stbMigrationStatus : migrationStatusesToMigrate)
|
||||
stbMigrationStatus.manageWithParentConnection(advancedDataSource.getConnection());
|
||||
|
||||
|
||||
advancedDataSource.getConnection().commit();
|
||||
}
|
||||
|
||||
private Long getLastMigrationFromDB(AdvancedDataSource advancedDataSource) throws Exception {
|
||||
|
||||
@@ -67,6 +67,12 @@ public abstract class BaseMigration implements MigrationModelInterface {
|
||||
return val != null && val == 1;
|
||||
}
|
||||
|
||||
protected boolean existsTable(Connection connection, String tableName) throws SQLException {
|
||||
String sql = Query.format("SELECT CAST(COUNT(*) AS BIT) AS exist FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N%s", tableName);
|
||||
|
||||
return UtilityDB.<Boolean>executeSimpleQueryOnlyFirstRowFirstColumn(connection, sql);
|
||||
}
|
||||
|
||||
|
||||
protected long executeInsertStatement(Connection connection, String sql) throws SQLException {
|
||||
long generatedId = -1;
|
||||
|
||||
@@ -10,6 +10,9 @@ public class Migration_20240212000001 extends BaseMigration implements Migration
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
if(!existsTable(advancedDataSource.getConnection(), "stb_transaction_log_db"))
|
||||
return;
|
||||
|
||||
dropTable(advancedDataSource.getConnection(), "stb_transaction_log_db");
|
||||
dropTable(advancedDataSource.getConnection(), "stb_transaction_log");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user