From 636d85ca409a41531210107e201262df7f5d9581 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Thu, 8 Sep 2022 09:58:52 +0200 Subject: [PATCH 1/3] Provides a fix for a wrong configuration path that was used by the application --- src/logic/application/ApplicationMigration.ts | 12 ++++++++++++ .../ApplicationMigrationPreviousToV200alpha1.ts | 15 +++++++++++++++ src/logic/application/ApplicationMigrator.ts | 17 +++++++++++++++++ src/logic/application/BootstrapApplication.ts | 8 +++++++- src/logic/configuration/Configuration.ts | 2 ++ src/logic/configuration/ConfigurationManager.ts | 3 ++- .../database/DatabaseMigratorV4ToV5.ts | 9 --------- 7 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 src/logic/application/ApplicationMigration.ts create mode 100644 src/logic/application/ApplicationMigrationPreviousToV200alpha1.ts create mode 100644 src/logic/application/ApplicationMigrator.ts diff --git a/src/logic/application/ApplicationMigration.ts b/src/logic/application/ApplicationMigration.ts new file mode 100644 index 00000000..af4e4be3 --- /dev/null +++ b/src/logic/application/ApplicationMigration.ts @@ -0,0 +1,12 @@ +/** + * For each version upgrade of the application that requires changes to the existing configuration, a new migrator + * that adheres to this interface can be implemented. This migrator will then be executed upon first opening a new + * version of the application. + */ +export default interface ApplicationMigration { + /** + * This method is called when the application is updated from one version to the next. All changes to the + * configuration of the application that apply to this specific version upgrade should be applied here. + */ + upgrade(): Promise; +} diff --git a/src/logic/application/ApplicationMigrationPreviousToV200alpha1.ts b/src/logic/application/ApplicationMigrationPreviousToV200alpha1.ts new file mode 100644 index 00000000..63c3d421 --- /dev/null +++ b/src/logic/application/ApplicationMigrationPreviousToV200alpha1.ts @@ -0,0 +1,15 @@ +import ApplicationMigration from "@/logic/application/ApplicationMigration"; +import ConfigurationManager from "@/logic/configuration/ConfigurationManager"; + +/** + * The default path of the application that's used for storing custom databases changed in version 2.0.0-alpha.1 of + * the application and needs to be reset here. + */ +export default class ApplicationMigrationPreviousToV200alpha1 implements ApplicationMigration { + public async upgrade(): Promise { + // Reset the configuration back to the default value. + const configManager = new ConfigurationManager(); + const defaultConfig = await configManager.getDefaultConfiguration(); + await configManager.writeConfiguration(defaultConfig); + } +} diff --git a/src/logic/application/ApplicationMigrator.ts b/src/logic/application/ApplicationMigrator.ts new file mode 100644 index 00000000..591654e4 --- /dev/null +++ b/src/logic/application/ApplicationMigrator.ts @@ -0,0 +1,17 @@ +import ApplicationMigration from "@/logic/application/ApplicationMigration"; +import ConfigurationManager from "@/logic/configuration/ConfigurationManager"; +import ApplicationMigrationPreviousToV200alpha1 from "@/logic/application/ApplicationMigrationPreviousToV200alpha1"; + +export default class ApplicationMigrator { + public async runMigrations(): Promise { + const configManager = new ConfigurationManager(); + const config = await configManager.readConfiguration(); + + // This key was only introduced in v2.0.0-alpha.1 of the application. If it's not present or invalid, we need + // to run the corresponding migration. + if (!config.configurationAppVersion) { + const migration = new ApplicationMigrationPreviousToV200alpha1(); + await migration.upgrade(); + } + } +} diff --git a/src/logic/application/BootstrapApplication.ts b/src/logic/application/BootstrapApplication.ts index a299b363..6a12de38 100644 --- a/src/logic/application/BootstrapApplication.ts +++ b/src/logic/application/BootstrapApplication.ts @@ -3,7 +3,7 @@ import Configuration from "@/logic/configuration/Configuration"; import { NetworkConfiguration, QueueManager } from "unipept-web-components"; import DockerCommunicator from "@/logic/communication/docker/DockerCommunicator"; import { Store } from "vuex"; -import CustomDatabaseManager from "@/logic/filesystem/docker/CustomDatabaseManager"; +import ApplicationMigrator from "@/logic/application/ApplicationMigrator"; /** * This class provides functions that need to be run when the application is started. All steps that are necessary for @@ -20,6 +20,7 @@ export default class BootstrapApplication { * Start and load the different components required for the application to function properly. */ public async loadApplicationComponents(): Promise { + await this.runApplicationMigrations(); const config = await this.initializeConfiguration(); this.initializeApi(config); this.initializeWorkers(config); @@ -61,4 +62,9 @@ export default class BootstrapApplication { private initializeProcessing(config: Configuration): Promise { return this.store.dispatch("initializeAssayQueue"); } + + private runApplicationMigrations(): Promise { + const applicationMigrator = new ApplicationMigrator(); + return applicationMigrator.runMigrations(); + } } diff --git a/src/logic/configuration/Configuration.ts b/src/logic/configuration/Configuration.ts index 060e50d8..45519b2c 100644 --- a/src/logic/configuration/Configuration.ts +++ b/src/logic/configuration/Configuration.ts @@ -3,4 +3,6 @@ export default interface Configuration { maxParallelRequests: number; dockerConfigurationSettings: string; customDbStorageLocation: string; + // The version of the application that was used to create this configuration. + configurationAppVersion: string; } diff --git a/src/logic/configuration/ConfigurationManager.ts b/src/logic/configuration/ConfigurationManager.ts index 36468580..2b72f7f1 100644 --- a/src/logic/configuration/ConfigurationManager.ts +++ b/src/logic/configuration/ConfigurationManager.ts @@ -79,7 +79,8 @@ export default class ConfigurationManager { maxParallelRequests: 3, dockerConfigurationSettings: Utils.isWindows() ? DockerCommunicator.WINDOWS_DEFAULT_SETTINGS : DockerCommunicator.UNIX_DEFAULT_SETTINGS, - customDbStorageLocation: customDbDir + customDbStorageLocation: customDbDir, + configurationAppVersion: this.app.getVersion() } } diff --git a/src/logic/filesystem/database/DatabaseMigratorV4ToV5.ts b/src/logic/filesystem/database/DatabaseMigratorV4ToV5.ts index 6b57855e..482873e1 100644 --- a/src/logic/filesystem/database/DatabaseMigratorV4ToV5.ts +++ b/src/logic/filesystem/database/DatabaseMigratorV4ToV5.ts @@ -9,21 +9,12 @@ import v4_to_v5 from "raw-loader!@/db/migrations/v4_to_v5.sql"; * that were used for the analysis of a specific sample. These details are required by the application to check if the * selected custom database is available for analysis (or not). * - * The migrator will also reset the default configuration values of the application since important changes have been - * made to these default values since the last version (the default Docker settings for Windows-systems have changed - * for example). - * * @author Pieter Verschaffelt */ export default class DatabaseMigratorV4ToV5 implements DatabaseMigrator { constructor(private readonly projectLocation: string) {} public async upgrade(database: Database.Database): Promise { - // Reset the configuration back to the default value. - const configManager = new ConfigurationManager(); - const defaultConfig = await configManager.getDefaultConfiguration(); - await configManager.writeConfiguration(defaultConfig); - // Now also migrate the SQL-database itself. For this to work, we need to read in all data and metadata for the // assays and convert to the newest database format. These data and metadata files will be temporarily kept // in memory. From 8c74a694c62b4717f9eca7ed0fe3dfa635afdc18 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Thu, 8 Sep 2022 10:52:13 +0200 Subject: [PATCH 2/3] Reference to Electron app was not properly imported --- .../application/ApplicationMigrationPreviousToV200alpha1.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/logic/application/ApplicationMigrationPreviousToV200alpha1.ts b/src/logic/application/ApplicationMigrationPreviousToV200alpha1.ts index 63c3d421..72b8790e 100644 --- a/src/logic/application/ApplicationMigrationPreviousToV200alpha1.ts +++ b/src/logic/application/ApplicationMigrationPreviousToV200alpha1.ts @@ -1,5 +1,6 @@ import ApplicationMigration from "@/logic/application/ApplicationMigration"; import ConfigurationManager from "@/logic/configuration/ConfigurationManager"; +import { app } from "@electron/remote"; /** * The default path of the application that's used for storing custom databases changed in version 2.0.0-alpha.1 of @@ -8,7 +9,7 @@ import ConfigurationManager from "@/logic/configuration/ConfigurationManager"; export default class ApplicationMigrationPreviousToV200alpha1 implements ApplicationMigration { public async upgrade(): Promise { // Reset the configuration back to the default value. - const configManager = new ConfigurationManager(); + const configManager = new ConfigurationManager(app); const defaultConfig = await configManager.getDefaultConfiguration(); await configManager.writeConfiguration(defaultConfig); } From e9a400d73838992563c0599c16e2766f16b72629 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Thu, 8 Sep 2022 11:12:21 +0200 Subject: [PATCH 3/3] Bump version to v2.0.0-alpha.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1544f8a0..987763e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unipept-desktop", - "version": "2.0.0-alpha.0", + "version": "2.0.0-alpha.1", "productName": "Unipept Desktop", "private": false, "author": "Unipept Team (Ghent University)",