Skip to content

Build your personal knowledge base with Trilium Notes

note history snapshots now have date from and date to

azivnerd1981eb6c3ca
diff --git a/migrations/0006__date_modified_from_to_in_note_history.sql b/migrations/0006__date_modified_from_to_in_note_history.sql
new file mode 100644
index 0000000000..6bcbd4f2ea
--- /dev/null
+++ b/migrations/0006__date_modified_from_to_in_note_history.sql
@@ -0,0 +1,3 @@
+CREATE TABLE notes_history_mig AS SELECT id, note_id, note_title, note_text, date_modified AS date_modified_from, date_modified AS date_modified_to FROM notes_history;
+DROP TABLE notes_history;
+ALTER TABLE notes_history_mig RENAME TO notes_history;
\ No newline at end of file
diff --git a/migrations/0007__readd_encryption_to_note_history.sql b/migrations/0007__readd_encryption_to_note_history.sql
new file mode 100644
index 0000000000..b5ecfb3cba
--- /dev/null
+++ b/migrations/0007__readd_encryption_to_note_history.sql
@@ -0,0 +1 @@
+ALTER TABLE notes_history ADD COLUMN encryption INTEGER DEFAULT 0
\ No newline at end of file
diff --git a/public/javascripts/note_history.js b/public/javascripts/note_history.js
index 2805355bc3..62a56c2e36 100644
--- a/public/javascripts/note_history.js
+++ b/public/javascripts/note_history.js
@@ -21,7 +21,7 @@ function showNoteHistoryDialog(noteId, noteHistoryId) {
globalHistoryItems = result;
for (const row of result) {
- const dateModified = getDateFromTS(row.date_modified);
+ const dateModified = getDateFromTS(row.date_modified_to);
$("#note-history-list").append($('<option>', {
value: row.id,
diff --git a/routes/api/note_history.js b/routes/api/note_history.js
index b4a34b644c..d60784dab0 100644
--- a/routes/api/note_history.js
+++ b/routes/api/note_history.js
@@ -8,7 +8,7 @@ const auth = require('../../services/auth');
router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {
const noteId = req.params.noteId;
- const history = await sql.getResults("select * from notes_history where note_id = ? order by date_modified desc", [noteId]);
+ const history = await sql.getResults("select * from notes_history where note_id = ? order by date_modified_to desc", [noteId]);
res.send(history);
});
diff --git a/routes/api/notes.js b/routes/api/notes.js
index 889e02725b..a530c9bac2 100644
--- a/routes/api/notes.js
+++ b/routes/api/notes.js
@@ -42,24 +42,26 @@ router.put('/:noteId', async (req, res, next) => {
const historyCutoff = now - historySnapshotTimeInterval;
- const history = await sql.getSingleResult("select id from notes_history where note_id = ? and date_modified >= ?", [noteId, historyCutoff]);
+ const history = await sql.getSingleResult("select id from notes_history where note_id = ? and date_modified_from >= ?", [noteId, historyCutoff]);
await sql.beginTransaction();
if (history) {
- await sql.execute("update notes_history set note_title = ?, note_text = ?, encryption = ? where id = ?", [
+ await sql.execute("update notes_history set note_title = ?, note_text = ?, encryption = ?, date_modified_to = ? where id = ?", [
note['detail']['note_title'],
note['detail']['note_text'],
note['detail']['encryption'],
+ now,
history['id']
]);
}
else {
- await sql.execute("insert into notes_history (note_id, note_title, note_text, encryption, date_modified) values (?, ?, ?, ?, ?)", [
+ await sql.execute("insert into notes_history (note_id, note_title, note_text, encryption, date_modified_from, date_modified_to) values (?, ?, ?, ?, ?, ?)", [
noteId,
note['detail']['note_title'],
note['detail']['note_text'],
note['detail']['encryption'],
+ now,
now
]);
}
diff --git a/services/migration.js b/services/migration.js
index 49cac161ee..c874c15d38 100644
--- a/services/migration.js
+++ b/services/migration.js
@@ -2,7 +2,7 @@ const backup = require('./backup');
const sql = require('./sql');
const fs = require('fs-extra');
-const APP_DB_VERSION = 5;
+const APP_DB_VERSION = 7;
const MIGRATIONS_DIR = "./migrations";
async function migrate() {