mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 01:48:32 +02:00
unify audit fields, fixes #102
This commit is contained in:
parent
933cce1b94
commit
03bf33630e
30
db/migrations/0094__unify_auditing_fields.sql
Normal file
30
db/migrations/0094__unify_auditing_fields.sql
Normal file
@ -0,0 +1,30 @@
|
||||
ALTER TABLE branches ADD dateCreated TEXT NOT NULL DEFAULT '1970-01-01T00:00:00.000Z';
|
||||
|
||||
CREATE TABLE `event_log_mig` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
`noteId` TEXT,
|
||||
`comment` TEXT,
|
||||
`dateCreated` TEXT NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO event_log_mig (id, noteId, comment, dateCreated)
|
||||
SELECT id, noteId, comment, dateAdded FROM event_log;
|
||||
|
||||
DROP TABLE event_log;
|
||||
ALTER TABLE event_log_mig RENAME TO event_log;
|
||||
|
||||
ALTER TABLE options ADD dateCreated TEXT NOT NULL DEFAULT '1970-01-01T00:00:00.000Z';
|
||||
|
||||
CREATE TABLE `recent_notes_mig` (
|
||||
`branchId` TEXT NOT NULL PRIMARY KEY,
|
||||
`notePath` TEXT NOT NULL,
|
||||
hash TEXT DEFAULT "" NOT NULL,
|
||||
`dateCreated` TEXT NOT NULL,
|
||||
isDeleted INT
|
||||
);
|
||||
|
||||
INSERT INTO recent_notes_mig (branchId, notePath, hash, dateCreated, isDeleted)
|
||||
SELECT branchId, notePath, hash, dateAccessed, isDeleted FROM recent_notes;
|
||||
|
||||
DROP TABLE recent_notes;
|
||||
ALTER TABLE recent_notes_mig RENAME TO recent_notes;
|
@ -27,7 +27,11 @@ class Branch extends Entity {
|
||||
this.isDeleted = false;
|
||||
}
|
||||
|
||||
this.dateModified = dateUtils.nowDate()
|
||||
if (!this.dateCreated) {
|
||||
this.dateCreated = dateUtils.nowDate();
|
||||
}
|
||||
|
||||
this.dateModified = dateUtils.nowDate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
const Entity = require('./entity');
|
||||
const dateUtils = require('../services/date_utils');
|
||||
|
||||
class RecentNote extends Entity {
|
||||
static get tableName() { return "recent_notes"; }
|
||||
static get primaryKeyName() { return "branchId"; }
|
||||
static get hashedProperties() { return ["branchId", "notePath", "dateAccessed", "isDeleted"]; }
|
||||
static get hashedProperties() { return ["branchId", "notePath", "dateCreated", "isDeleted"]; }
|
||||
|
||||
beforeSaving() {
|
||||
super.beforeSaving();
|
||||
|
||||
if (!this.isDeleted) {
|
||||
this.isDeleted = false;
|
||||
}
|
||||
|
||||
if (!this.dateCreated) {
|
||||
this.dateCreated = dateUtils.nowDate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RecentNote;
|
@ -19,7 +19,7 @@ async function showDialog() {
|
||||
$list.html('');
|
||||
|
||||
for (const event of result) {
|
||||
const dateTime = utils.formatDateTime(utils.parseDate(event.dateAdded));
|
||||
const dateTime = utils.formatDateTime(utils.parseDate(event.dateCreated));
|
||||
|
||||
if (event.noteId) {
|
||||
const noteLink = await linkService.createNoteLink(event.noteId).prop('outerHTML');
|
||||
|
@ -5,7 +5,7 @@ const sql = require('../../services/sql');
|
||||
async function getEventLog() {
|
||||
await deleteOld();
|
||||
|
||||
return await sql.getRows("SELECT * FROM event_log ORDER BY dateAdded DESC");
|
||||
return await sql.getRows("SELECT * FROM event_log ORDER BY dateCreated DESC");
|
||||
}
|
||||
|
||||
async function deleteOld() {
|
||||
|
@ -16,7 +16,7 @@ async function getRecentNotes() {
|
||||
recent_notes.isDeleted = 0
|
||||
AND branches.isDeleted = 0
|
||||
ORDER BY
|
||||
dateAccessed DESC
|
||||
dateCreated DESC
|
||||
LIMIT 200`);
|
||||
}
|
||||
|
||||
@ -26,9 +26,7 @@ async function addRecentNote(req) {
|
||||
|
||||
await new RecentNote({
|
||||
branchId: branchId,
|
||||
notePath: notePath,
|
||||
dateAccessed: dateUtils.nowDate(),
|
||||
isDeleted: 0
|
||||
notePath: notePath
|
||||
}).save();
|
||||
|
||||
await optionService.setOption('startNotePath', notePath);
|
||||
|
@ -3,7 +3,7 @@
|
||||
const build = require('./build');
|
||||
const packageJson = require('../../package');
|
||||
|
||||
const APP_DB_VERSION = 93;
|
||||
const APP_DB_VERSION = 94;
|
||||
|
||||
module.exports = {
|
||||
appVersion: packageJson.version,
|
||||
|
@ -10,7 +10,7 @@ async function addNoteEvent(noteId, comment) {
|
||||
await sql.insert('event_log', {
|
||||
noteId : noteId,
|
||||
comment: comment,
|
||||
dateAdded: dateUtils.nowDate()
|
||||
dateCreated: dateUtils.nowDate()
|
||||
});
|
||||
|
||||
log.info("Event log for " + noteId + ": " + comment);
|
||||
|
@ -127,7 +127,7 @@ async function updateOptions(entity, sourceId) {
|
||||
async function updateRecentNotes(entity, sourceId) {
|
||||
const orig = await sql.getRowOrNull("SELECT * FROM recent_notes WHERE branchId = ?", [entity.branchId]);
|
||||
|
||||
if (orig === null || orig.dateAccessed < entity.dateAccessed) {
|
||||
if (orig === null || orig.dateCreated < entity.dateCreated) {
|
||||
await sql.transactional(async () => {
|
||||
await sql.replace('recent_notes', entity);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user