From cdc2721ac1102529259aa204dc9d4766cba9185d Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 16 Dec 2020 20:58:43 +0100 Subject: [PATCH] DB migration fixes --- db/migrations/0174__move_hash_to_entity_changes.sql | 8 +++++--- src/services/consistency_checks.js | 8 +++++++- src/services/migration.js | 2 +- src/services/options_init.js | 1 - src/services/sql.js | 2 ++ 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/db/migrations/0174__move_hash_to_entity_changes.sql b/db/migrations/0174__move_hash_to_entity_changes.sql index 2f7500c48..da93b5961 100644 --- a/db/migrations/0174__move_hash_to_entity_changes.sql +++ b/db/migrations/0174__move_hash_to_entity_changes.sql @@ -5,10 +5,12 @@ CREATE TABLE IF NOT EXISTS "mig_entity_changes" ( `hash` TEXT NOT NULL, `isErased` INT NOT NULL, `sourceId` TEXT NOT NULL, - `isSynced` INTEGER NOT NULL); + `isSynced` INTEGER NOT NULL, + `utcDateChanged` TEXT NOT NULL + ); -INSERT INTO mig_entity_changes (entityName, entityId, hash, sourceId, isSynced, isErased) - SELECT entityName, entityId, '', sourceId, isSynced, isErased FROM entity_changes; +INSERT INTO mig_entity_changes (entityName, entityId, hash, sourceId, isSynced, isErased, utcDateChanged) + SELECT entityName, entityId, '', sourceId, isSynced, isErased, utcDateChanged FROM entity_changes; UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM api_tokens WHERE apiTokenId = entityId), '') WHERE entityName = 'api_tokens'; UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM attributes WHERE attributeId = entityId), '') WHERE entityName = 'attributes'; diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index cb7044c9f..99ee0276c 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -465,7 +465,13 @@ class ConsistencyChecks { if (this.autoFix) { const entity = repository.getEntity(`SELECT * FROM ${entityName} WHERE ${key} = ?`, [entityId]); - entityChangesService.addEntityChange(entityName, entityId, entity.generateHash()); + entityChangesService.addEntityChange({ + entityName, + entityId, + hash: entity.generateHash(), + isErased: false, + utcDateChanged: entity.getUtcDateChanged() + }, null); logFix(`Created missing entity change for entityName=${entityName}, entityId=${entityId}`); } else { diff --git a/src/services/migration.js b/src/services/migration.js index 4ad904594..72e32b669 100644 --- a/src/services/migration.js +++ b/src/services/migration.js @@ -62,7 +62,7 @@ async function migrate() { } // not using repository because of changed utcDateModified column in migration 129 - sql.execute(`UPDATE options SET value = ? WHERE name = ?`, [mig.dbVersion, "dbVersion"]); + sql.execute(`UPDATE options SET value = ? WHERE name = ?`, [mig.dbVersion.toString(), "dbVersion"]); }); log.info("Migration to version " + mig.dbVersion + " has been successful."); diff --git a/src/services/options_init.js b/src/services/options_init.js index 32768d21f..66fac2477 100644 --- a/src/services/options_init.js +++ b/src/services/options_init.js @@ -58,7 +58,6 @@ function initNotSyncedOptions(initialized, startNotePath = 'root', opts = {}) { const defaultOptions = [ { name: 'noteRevisionSnapshotTimeInterval', value: '600', isSynced: true }, { name: 'protectedSessionTimeout', value: '600', isSynced: true }, - { name: 'hoistedNoteId', value: 'root', isSynced: false }, { name: 'zoomFactor', value: '1.0', isSynced: false }, { name: 'mainFontSize', value: '100', isSynced: false }, { name: 'treeFontSize', value: '100', isSynced: false }, diff --git a/src/services/sql.js b/src/services/sql.js index e825113b4..f7896d732 100644 --- a/src/services/sql.js +++ b/src/services/sql.js @@ -210,6 +210,8 @@ function wrap(query, func) { return null } + + throw e; } const milliseconds = Date.now() - startTimestamp;