fix migration in electron build

This commit is contained in:
azivner 2017-12-06 20:58:59 -05:00
parent d467fbdff3
commit bbd1774815
6 changed files with 18 additions and 9 deletions

View File

@ -31,7 +31,7 @@ function pad(data) {
function encrypt(key, iv, plainText) { function encrypt(key, iv, plainText) {
if (!key) { if (!key) {
throwError("No data key!"); throw new Error("No data key!");
} }
const plainTextBuffer = Buffer.from(plainText); const plainTextBuffer = Buffer.from(plainText);

View File

@ -5,7 +5,16 @@ const fs = require('fs-extra');
const log = require('./log'); const log = require('./log');
const app_info = require('./app_info'); 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() { async function migrate() {
const migrations = []; const migrations = [];
@ -58,7 +67,7 @@ async function migrate() {
await migrationModule(db); await migrationModule(db);
} }
else { else {
throwError("Unknown migration type " + mig.type); throw new Error("Unknown migration type " + mig.type);
} }
await options.setOption("db_version", mig.dbVersion); await options.setOption("db_version", mig.dbVersion);

View File

@ -28,7 +28,7 @@ async function createNewNote(parentNoteId, note) {
await sync_table.addNoteReorderingSync(parentNoteId); await sync_table.addNoteReorderingSync(parentNoteId);
} }
else { else {
throwError('Unknown target: ' + note.target); throw new Error('Unknown target: ' + note.target);
} }

View File

@ -10,7 +10,7 @@ async function getOption(optName) {
const row = await sql.getSingleResultOrNull("SELECT opt_value FROM options WHERE opt_name = ?", [optName]); const row = await sql.getSingleResultOrNull("SELECT opt_value FROM options WHERE opt_name = ?", [optName]);
if (!row) { if (!row) {
throwError("Option " + optName + " doesn't exist"); throw new Error("Option " + optName + " doesn't exist");
} }
return row['opt_value']; return row['opt_value'];

View File

@ -9,7 +9,7 @@ module.exports = function(req) {
function getDataKey() { function getDataKey() {
if (!isProtectedSessionAvailable()) { if (!isProtectedSessionAvailable()) {
throwError("Protected session is not available"); throw new Error("Protected session is not available");
} }
return protected_session.getDataKey(req); return protected_session.getDataKey(req);

View File

@ -157,7 +157,7 @@ async function pullSync(syncContext) {
await syncUpdate.updateRecentNotes(resp, syncContext.sourceId); await syncUpdate.updateRecentNotes(resp, syncContext.sourceId);
} }
else { else {
throwError("Unrecognized entity type " + sync.entity_name); throw new Error("Unrecognized entity type " + sync.entity_name);
} }
await setLastSyncedPull(sync.id); 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]); entity = await sql.getSingleResult('SELECT * FROM recent_notes WHERE note_tree_id = ?', [sync.entity_id]);
} }
else { else {
throwError("Unrecognized entity type " + sync.entity_name); throw new Error("Unrecognized entity type " + sync.entity_name);
} }
if (!entity) { if (!entity) {
@ -302,7 +302,7 @@ async function syncRequest(syncContext, method, uri, body) {
return await rp(options); return await rp(options);
} }
catch (e) { catch (e) {
throwError("Request to " + method + " " + fullUri + " failed, inner exception: " + e.stack); throw new Error("Request to " + method + " " + fullUri + " failed, inner exception: " + e.stack);
} }
} }