diff --git a/src/main/index.ts b/src/main/index.ts index 5293cda8..93481f61 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -53,6 +53,18 @@ if (process.defaultApp) { app.setAsDefaultProtocolClient(PROTOCOL); } +const runMigrations = async () => { + await knexClient.migrate.list(migrationConfig).then((result) => { + logger.log( + "Migrations to run:", + result[1].map((migration) => migration.name) + ); + }); + + await knexClient.migrate.latest(migrationConfig); + await knexClient.destroy(); +}; + // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. @@ -64,15 +76,7 @@ app.whenReady().then(async () => { return net.fetch(url.pathToFileURL(decodeURI(filePath)).toString()); }); - await knexClient.migrate.list(migrationConfig).then((result) => { - logger.log( - "Migrations to run:", - result[1].map((migration) => migration.name) - ); - }); - - await knexClient.migrate - .latest(migrationConfig) + await runMigrations() .then(() => { logger.log("Migrations executed successfully"); }) @@ -80,8 +84,6 @@ app.whenReady().then(async () => { logger.log("Migrations failed to run:", err); }); - await knexClient.destroy(); - await dataSource.initialize(); await import("./main");