feat: refactor knex promises

This commit is contained in:
Zamitto 2024-09-02 12:54:55 -03:00
parent 158b878883
commit 88737cf80d

View file

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