Skip to content

Commit

Permalink
Merge pull request #200 from unipept/fix/wrong-default-config-path
Browse files Browse the repository at this point in the history
Fix wrong default config path
  • Loading branch information
pverscha authored Sep 8, 2022
2 parents f4aea6b + e9a400d commit f2e94bf
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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)",
Expand Down
12 changes: 12 additions & 0 deletions src/logic/application/ApplicationMigration.ts
Original file line number Diff line number Diff line change
@@ -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<void>;
}
16 changes: 16 additions & 0 deletions src/logic/application/ApplicationMigrationPreviousToV200alpha1.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
// Reset the configuration back to the default value.
const configManager = new ConfigurationManager(app);
const defaultConfig = await configManager.getDefaultConfiguration();
await configManager.writeConfiguration(defaultConfig);
}
}
17 changes: 17 additions & 0 deletions src/logic/application/ApplicationMigrator.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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();
}
}
}
8 changes: 7 additions & 1 deletion src/logic/application/BootstrapApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<void> {
await this.runApplicationMigrations();
const config = await this.initializeConfiguration();
this.initializeApi(config);
this.initializeWorkers(config);
Expand Down Expand Up @@ -61,4 +62,9 @@ export default class BootstrapApplication {
private initializeProcessing(config: Configuration): Promise<void> {
return this.store.dispatch("initializeAssayQueue");
}

private runApplicationMigrations(): Promise<void> {
const applicationMigrator = new ApplicationMigrator();
return applicationMigrator.runMigrations();
}
}
2 changes: 2 additions & 0 deletions src/logic/configuration/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion src/logic/configuration/ConfigurationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
9 changes: 0 additions & 9 deletions src/logic/filesystem/database/DatabaseMigratorV4ToV5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
// 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.
Expand Down

0 comments on commit f2e94bf

Please sign in to comment.