From d79f179659e38013c5ddcb231baf07029f7bf8af Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Mon, 18 Apr 2022 17:09:33 +0200 Subject: [PATCH] #663 - ensure settings exist on migration error: error during migration leads to missing settings (database table still empty) -> this prevents fetch of status --> user stuck in progress indicator forever --- .../budgetmaster/migration/MigrationService.java | 2 +- .../budgetmaster/migration/MigrationTask.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationService.java b/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationService.java index 2f29e4ec9..b5aaf0f91 100644 --- a/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationService.java +++ b/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationService.java @@ -44,7 +44,7 @@ public class MigrationService this.transactionRepository = transactionRepository; this.templateRepository = templateRepository; this.databaseConfig = databaseConfig; - this.migrationTask = new MigrationTask(applicationSupportFolder); + this.migrationTask = new MigrationTask(applicationSupportFolder, settingsService); this.scheduler = scheduler; } diff --git a/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationTask.java b/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationTask.java index 99bce21bd..60f5340d3 100644 --- a/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationTask.java +++ b/BudgetMasterServer/src/main/java/de/deadlocker8/budgetmaster/migration/MigrationTask.java @@ -1,5 +1,6 @@ package de.deadlocker8.budgetmaster.migration; +import de.deadlocker8.budgetmaster.settings.SettingsService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,14 +28,17 @@ public class MigrationTask implements Runnable private final Path applicationSupportFolder; + private final SettingsService settingsService; + private MigrationArguments migrationArguments; private MigrationStatus migrationStatus; private List<String> collectedStdout; private List<String> summary; - public MigrationTask(Path applicationSupportFolder) + public MigrationTask(Path applicationSupportFolder, SettingsService settingsService) { this.applicationSupportFolder = applicationSupportFolder; + this.settingsService = settingsService; this.migrationStatus = MigrationStatus.NOT_RUNNING; } @@ -72,6 +76,11 @@ public class MigrationTask implements Runnable } finally { + // if any error happens during migration the settings table might be still empty and lead to errors + // and an infinite progress indicator loop during fetch of the migration status due to SettingsAdvice.class + // Therefore ensure settings exist at this point + settingsService.createDefaultSettingsIfNotExists(); + Files.deleteIfExists(migratorPath); } -- GitLab