Skip to content

Commit

Permalink
Merge pull request #951 from hydralauncher/fix/knex-not-creating-data…
Browse files Browse the repository at this point in the history
…base-directory

fix: ensure database directory exists before running knex
  • Loading branch information
zamitto authored Sep 13, 2024
2 parents 02ca506 + 123812a commit a295003
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/main/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import path from "node:path";

export const defaultDownloadsPath = app.getPath("downloads");

export const databasePath = path.join(
app.getPath("appData"),
"hydra",
"hydra.db"
);
export const databaseDirectory = path.join(app.getPath("appData"), "hydra");
export const databasePath = path.join(databaseDirectory, "hydra.db");

export const logsPath = path.join(app.getPath("appData"), "hydra", "logs");

Expand Down
6 changes: 6 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import updater from "electron-updater";
import i18n from "i18next";
import path from "node:path";
import url from "node:url";
import fs from "node:fs";
import { electronApp, optimizer } from "@electron-toolkit/utils";
import { logger, PythonInstance, WindowManager } from "@main/services";
import { dataSource } from "@main/data-source";
import resources from "@locales";
import { userPreferencesRepository } from "@main/repository";
import { knexClient, migrationConfig } from "./knex-client";
import { databaseDirectory } from "./constants";

const { autoUpdater } = updater;

Expand Down Expand Up @@ -54,6 +56,10 @@ if (process.defaultApp) {
}

const runMigrations = async () => {
if (!fs.existsSync(databaseDirectory)) {
fs.mkdirSync(databaseDirectory, { recursive: true });
}

await knexClient.migrate.list(migrationConfig).then((result) => {
logger.log(
"Migrations to run:",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2879,10 +2879,10 @@ axe-core@=4.7.0:
resolved "https://registry.npmjs.org/axe-core/-/axe-core-4.7.0.tgz"
integrity sha512-M0JtH+hlOL5pLQwHOLNYZaXuhqmvS8oExsqB1SBYgA4Dk7u/xx+YdGHXaK5pyUfed5mYXdlYiphWq3G8cRi5JQ==

axios@^1.6.8:
version "1.6.8"
resolved "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz"
integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==
axios@^1.7.7:
version "1.7.7"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f"
integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
Expand Down

0 comments on commit a295003

Please sign in to comment.