From bbd177481523bf6d7c9388b0ddf65af7f5c61e6b Mon Sep 17 00:00:00 2001 From: azivner Date: Wed, 6 Dec 2017 20:58:59 -0500 Subject: [PATCH] fix migration in electron build --- services/data_encryption.js | 2 +- services/migration.js | 13 +++++++++++-- services/notes.js | 2 +- services/options.js | 2 +- services/request_context.js | 2 +- services/sync.js | 6 +++--- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/services/data_encryption.js b/services/data_encryption.js index 84b8174e9..31ebf9044 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 5a02cb05c..437c8aac1 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 c57d0d05a..95e8cc4fb 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 a14b2d9ed..bac7f6da8 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 ce43d926f..bb12d6ff7 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 92d8964b3..91d350eb3 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); } }