From 297da47b34fde6f226d11acbef65e3467ddffe31 Mon Sep 17 00:00:00 2001 From: azivner Date: Thu, 26 Oct 2017 21:53:26 -0400 Subject: [PATCH] fix sync of audit log --- migrations/0014__change_audit_log_id.sql | 16 ++++++++++++++++ public/javascripts/tree.js | 4 ++++ services/migration.js | 2 +- services/sync.js | 2 -- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 migrations/0014__change_audit_log_id.sql diff --git a/migrations/0014__change_audit_log_id.sql b/migrations/0014__change_audit_log_id.sql new file mode 100644 index 000000000..c553ecfd0 --- /dev/null +++ b/migrations/0014__change_audit_log_id.sql @@ -0,0 +1,16 @@ +CREATE TABLE `audit_log_mig` ( + `id` TEXT NOT NULL PRIMARY KEY, + `date_modified` INTEGER NOT NULL, + `category` TEXT NOT NULL, + `browser_id` TEXT, + `note_id` TEXT, + `change_from` TEXT, + `change_to` TEXT, + `comment` TEXT +); + +INSERT INTO audit_log_mig (id, date_modified, category, browser_id, note_id, change_from, change_to) + SELECT id, date_modified, category, browser_id, note_id, change_from, change_to FROM audit_log; + +DROP TABLE audit_log; +ALTER TABLE audit_log_mig RENAME TO audit_log; \ No newline at end of file diff --git a/public/javascripts/tree.js b/public/javascripts/tree.js index 40c629a98..a5d1e6906 100644 --- a/public/javascripts/tree.js +++ b/public/javascripts/tree.js @@ -102,6 +102,10 @@ setInterval(() => { // if the user got logged out then we should display the page // here we do that by reloading which will force the redirect if the user is really logged out window.location.reload(true); + }, + 409: () => { + // 409 means we need to migrate database, reload will take care of it + window.location.reload(true); } } }); diff --git a/services/migration.js b/services/migration.js index 7b3564a50..01126d09e 100644 --- a/services/migration.js +++ b/services/migration.js @@ -3,7 +3,7 @@ const sql = require('./sql'); const fs = require('fs-extra'); const log = require('./log'); -const APP_DB_VERSION = 13; +const APP_DB_VERSION = 14; const MIGRATIONS_DIR = "./migrations"; async function migrate() { diff --git a/services/sync.js b/services/sync.js index 6059a218b..217c384ae 100644 --- a/services/sync.js +++ b/services/sync.js @@ -135,8 +135,6 @@ async function putChanged(changed) { } for (const audit of changed.audit_log) { - delete audit['id']; - await sql.insert("audit_log", audit, true); log.info("Update/sync audit_log for noteId=" + audit.note_id);