Skip to content

Build your personal knowledge base with Trilium Notes

fix migration in electron build

azivnerbbd177481523
diff --git a/services/data_encryption.js b/services/data_encryption.js
index 84b8174e92..31ebf90443 100644
--- a/services/data_encryption.js
+++ b/services/data_encryption.js
@@ -31,7 +31,7 @@ function pad(data) {
function encrypt(key, iv, plainText) {
if (!key) {
- throwError("No data key!");
+ throw new Error("No data key!");
}
const plainTextBuffer = Buffer.from(plainText);
diff --git a/services/migration.js b/services/migration.js
index 5a02cb05cc..437c8aac1e 100644
--- a/services/migration.js
+++ b/services/migration.js
@@ -5,7 +5,16 @@ const fs = require('fs-extra');
const log = require('./log');
const app_info = require('./app_info');
-const MIGRATIONS_DIR = "migrations";
+let MIGRATIONS_DIR = "migrations";
+
+if (!fs.existsSync(MIGRATIONS_DIR) && isElectron()) {
+ MIGRATIONS_DIR = "resources/app/migrations";
+}
+
+if (!fs.existsSync(MIGRATIONS_DIR)) {
+ log.error("Could not find migration directory: " + MIGRATIONS_DIR);
+ process.exit(1);
+}
async function migrate() {
const migrations = [];
@@ -58,7 +67,7 @@ async function migrate() {
await migrationModule(db);
}
else {
- throwError("Unknown migration type " + mig.type);
+ throw new Error("Unknown migration type " + mig.type);
}
await options.setOption("db_version", mig.dbVersion);
diff --git a/services/notes.js b/services/notes.js
index c57d0d05ad..95e8cc4fb0 100644
--- a/services/notes.js
+++ b/services/notes.js
@@ -28,7 +28,7 @@ async function createNewNote(parentNoteId, note) {
await sync_table.addNoteReorderingSync(parentNoteId);
}
else {
- throwError('Unknown target: ' + note.target);
+ throw new Error('Unknown target: ' + note.target);
}
diff --git a/services/options.js b/services/options.js
index a14b2d9ede..bac7f6da80 100644
--- a/services/options.js
+++ b/services/options.js
@@ -10,7 +10,7 @@ async function getOption(optName) {
const row = await sql.getSingleResultOrNull("SELECT opt_value FROM options WHERE opt_name = ?", [optName]);
if (!row) {
- throwError("Option " + optName + " doesn't exist");
+ throw new Error("Option " + optName + " doesn't exist");
}
return row['opt_value'];
diff --git a/services/request_context.js b/services/request_context.js
index ce43d926ff..bb12d6ff71 100644
--- a/services/request_context.js
+++ b/services/request_context.js
@@ -9,7 +9,7 @@ module.exports = function(req) {
function getDataKey() {
if (!isProtectedSessionAvailable()) {
- throwError("Protected session is not available");
+ throw new Error("Protected session is not available");
}
return protected_session.getDataKey(req);
diff --git a/services/sync.js b/services/sync.js
index 92d8964b3d..91d350eb3a 100644
--- a/services/sync.js
+++ b/services/sync.js
@@ -157,7 +157,7 @@ async function pullSync(syncContext) {
await syncUpdate.updateRecentNotes(resp, syncContext.sourceId);
}
else {
- throwError("Unrecognized entity type " + sync.entity_name);
+ throw new Error("Unrecognized entity type " + sync.entity_name);
}
await setLastSyncedPull(sync.id);
@@ -228,7 +228,7 @@ async function readAndPushEntity(sync, syncContext) {
entity = await sql.getSingleResult('SELECT * FROM recent_notes WHERE note_tree_id = ?', [sync.entity_id]);
}
else {
- throwError("Unrecognized entity type " + sync.entity_name);
+ throw new Error("Unrecognized entity type " + sync.entity_name);
}
if (!entity) {
@@ -302,7 +302,7 @@ async function syncRequest(syncContext, method, uri, body) {
return await rp(options);
}
catch (e) {
- throwError("Request to " + method + " " + fullUri + " failed, inner exception: " + e.stack);
+ throw new Error("Request to " + method + " " + fullUri + " failed, inner exception: " + e.stack);
}
}