mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
unifying surrogate keys for event log and options, fixes #103
This commit is contained in:
parent
a30734f1bc
commit
cab54a458f
29
db/migrations/0096__unify_surrogate_keys.sql
Normal file
29
db/migrations/0096__unify_surrogate_keys.sql
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
CREATE TABLE `event_log_mig` (
|
||||||
|
`eventId` TEXT NOT NULL PRIMARY KEY,
|
||||||
|
`noteId` TEXT,
|
||||||
|
`comment` TEXT,
|
||||||
|
`dateCreated` TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO event_log_mig (eventId, noteId, comment, dateCreated)
|
||||||
|
SELECT id, noteId, comment, dateCreated FROM event_log;
|
||||||
|
|
||||||
|
DROP TABLE event_log;
|
||||||
|
ALTER TABLE event_log_mig RENAME TO event_log;
|
||||||
|
|
||||||
|
create table options_mig
|
||||||
|
(
|
||||||
|
optionId TEXT NOT NULL PRIMARY KEY,
|
||||||
|
name TEXT not null,
|
||||||
|
value TEXT,
|
||||||
|
dateModified INT,
|
||||||
|
isSynced INTEGER default 0 not null,
|
||||||
|
hash TEXT default "" not null,
|
||||||
|
dateCreated TEXT default '1970-01-01T00:00:00.000Z' not null
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO options_mig (optionId, name, value, dateModified, isSynced, hash, dateCreated)
|
||||||
|
SELECT name || "_key", name, value, dateModified, isSynced, hash, dateCreated FROM options;
|
||||||
|
|
||||||
|
DROP TABLE options;
|
||||||
|
ALTER TABLE options_mig RENAME TO options;
|
@ -13,11 +13,6 @@ let codeEditorInitialized;
|
|||||||
async function show() {
|
async function show() {
|
||||||
codeEditorInitialized = false;
|
codeEditorInitialized = false;
|
||||||
|
|
||||||
// if the note is empty, it doesn't make sense to do render-only since nothing will be rendered
|
|
||||||
if (!noteDetailService.getCurrentNote().content.trim()) {
|
|
||||||
toggleEdit();
|
|
||||||
}
|
|
||||||
|
|
||||||
$noteDetailRender.show();
|
$noteDetailRender.show();
|
||||||
|
|
||||||
await render();
|
await render();
|
||||||
@ -61,6 +56,11 @@ async function render() {
|
|||||||
|
|
||||||
$noteDetailRender.html(bundle.html);
|
$noteDetailRender.html(bundle.html);
|
||||||
|
|
||||||
|
// if the note is empty, it doesn't make sense to do render-only since nothing will be rendered
|
||||||
|
if (!bundle.html.trim()) {
|
||||||
|
toggleEdit();
|
||||||
|
}
|
||||||
|
|
||||||
await bundleService.executeBundle(bundle);
|
await bundleService.executeBundle(bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,19 +3,9 @@
|
|||||||
const sql = require('../../services/sql');
|
const sql = require('../../services/sql');
|
||||||
|
|
||||||
async function getEventLog() {
|
async function getEventLog() {
|
||||||
await deleteOld();
|
|
||||||
|
|
||||||
return await sql.getRows("SELECT * FROM event_log ORDER BY dateCreated DESC");
|
return await sql.getRows("SELECT * FROM event_log ORDER BY dateCreated DESC");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteOld() {
|
|
||||||
const cutoffId = await sql.getValue("SELECT id FROM event_log ORDER BY id DESC LIMIT 1000, 1");
|
|
||||||
|
|
||||||
if (cutoffId) {
|
|
||||||
await sql.execute("DELETE FROM event_log WHERE id < ?", [cutoffId]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getEventLog
|
getEventLog
|
||||||
};
|
};
|
@ -3,7 +3,7 @@
|
|||||||
const build = require('./build');
|
const build = require('./build');
|
||||||
const packageJson = require('../../package');
|
const packageJson = require('../../package');
|
||||||
|
|
||||||
const APP_DB_VERSION = 95;
|
const APP_DB_VERSION = 96;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
appVersion: packageJson.version,
|
appVersion: packageJson.version,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const dateUtils = require('./date_utils');
|
const dateUtils = require('./date_utils');
|
||||||
|
const utils = require('./utils');
|
||||||
const log = require('./log');
|
const log = require('./log');
|
||||||
|
|
||||||
async function addEvent(comment) {
|
async function addEvent(comment) {
|
||||||
@ -8,9 +9,10 @@ async function addEvent(comment) {
|
|||||||
|
|
||||||
async function addNoteEvent(noteId, comment) {
|
async function addNoteEvent(noteId, comment) {
|
||||||
await sql.insert('event_log', {
|
await sql.insert('event_log', {
|
||||||
noteId : noteId,
|
eventId: utils.newEntityId(),
|
||||||
comment: comment,
|
noteId : noteId,
|
||||||
dateCreated: dateUtils.nowDate()
|
comment: comment,
|
||||||
|
dateCreated: dateUtils.nowDate()
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info("Event log for " + noteId + ": " + comment);
|
log.info("Event log for " + noteId + ": " + comment);
|
||||||
|
@ -207,13 +207,12 @@ const primaryKeys = {
|
|||||||
"notes": "noteId",
|
"notes": "noteId",
|
||||||
"branches": "branchId",
|
"branches": "branchId",
|
||||||
"note_revisions": "noteRevisionId",
|
"note_revisions": "noteRevisionId",
|
||||||
"option": "name",
|
|
||||||
"recent_notes": "branchId",
|
"recent_notes": "branchId",
|
||||||
"images": "imageId",
|
"images": "imageId",
|
||||||
"note_images": "noteImageId",
|
"note_images": "noteImageId",
|
||||||
"labels": "labelId",
|
"labels": "labelId",
|
||||||
"api_tokens": "apiTokenId",
|
"api_tokens": "apiTokenId",
|
||||||
"options": "name"
|
"options": "optionId"
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getEntityRow(entityName, entityId) {
|
async function getEntityRow(entityName, entityId) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user