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)", 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..72b8790e --- /dev/null +++ b/src/logic/application/ApplicationMigrationPreviousToV200alpha1.ts @@ -0,0 +1,16 @@ +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 + * 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(app); + 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.