diff --git a/drizzle.config.ts b/drizzle.config.ts index dc713b7..ee2c2ca 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -1,13 +1,14 @@ import type { Config } from "drizzle-kit"; import path from "path"; +import { getUserDataPath } from "./src/paths/paths"; -const devDbPath = path.resolve("./userData/sqlite.db"); +const dbPath = path.join(getUserDataPath(), "sqlite.db"); export default { schema: "./src/db/schema.ts", out: "./drizzle", dialect: "sqlite", dbCredentials: { - url: devDbPath, + url: dbPath, }, } satisfies Config; diff --git a/src/db/index.ts b/src/db/index.ts index 34453cd..62b3794 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -62,7 +62,10 @@ export function initializeDatabase(): BetterSQLite3Database & { try { // Run migrations programmatically - const migrationsFolder = path.join(process.cwd(), "drizzle"); + + const migrationsFolder = path.join(__dirname, "..", "..", "drizzle"); + + console.log("MIGRATIONS FOLDER INITIALIZE", migrationsFolder); // Verify migrations folder exists if (!fs.existsSync(migrationsFolder)) { diff --git a/src/main.ts b/src/main.ts index bdc49bc..2ea64f2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -50,9 +50,10 @@ const createWindow = () => { path.join(__dirname, "../renderer/main_window/index.html") ); } - - // Open the DevTools. - mainWindow.webContents.openDevTools(); + if (process.env.NODE_ENV === "development") { + // Open the DevTools. + mainWindow.webContents.openDevTools(); + } }; // This method will be called when Electron has finished diff --git a/src/paths/paths.ts b/src/paths/paths.ts index df214fd..cfa94ee 100644 --- a/src/paths/paths.ts +++ b/src/paths/paths.ts @@ -15,8 +15,8 @@ export function getUserDataPath(): string { const electron = getElectron(); // When running in Electron and app is ready - if (electron?.app?.isReady() && process.env.NODE_ENV !== "development") { - return electron.app.getPath("userData"); + if (process.env.NODE_ENV !== "development") { + return electron!.app.getPath("userData"); } // For development or when the Electron app object isn't available