From 88737cf80d2efb58f8fd6143213bab7cf9517dec Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:54:55 -0300 Subject: [PATCH] feat: refactor knex promises --- src/main/index.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) 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");