feat: write migrations

This commit is contained in:
Zamitto 2024-08-22 23:50:35 -03:00
parent 52069f7036
commit 89399a6da4
12 changed files with 358 additions and 92 deletions

View file

@ -9,6 +9,7 @@ import { logger, PythonInstance, WindowManager } from "@main/services";
import { dataSource } from "@main/data-source";
import * as resources from "@locales";
import { userPreferencesRepository } from "@main/repository";
import { knexClient, migrationConfig } from "./knex-client";
const { autoUpdater } = updater;
@ -63,8 +64,25 @@ 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)
.then(() => {
logger.log("Migrations executed successfully");
})
.catch((err) => {
logger.log("Migrations failed to run:", err);
});
await knexClient.destroy();
await dataSource.initialize();
await dataSource.runMigrations();
await import("./main");