Skip to content

Build your personal knowledge base with Trilium Notes

fix sync of audit log

azivner297da47b34fd
diff --git a/migrations/0014__change_audit_log_id.sql b/migrations/0014__change_audit_log_id.sql
new file mode 100644
index 0000000000..c553ecfd01
--- /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 40c629a98d..a5d1e6906e 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 7b3564a50f..01126d09ed 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 6059a218bc..217c384aec 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);