unifying surrogate keys for event log and options, fixes #103

This commit is contained in:
azivner 2018-05-26 23:25:09 -04:00
parent a30734f1bc
commit cab54a458f
6 changed files with 41 additions and 21 deletions

View 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;

View File

@ -13,11 +13,6 @@ let codeEditorInitialized;
async function show() {
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();
await render();
@ -61,6 +56,11 @@ async function render() {
$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);
}

View File

@ -3,19 +3,9 @@
const sql = require('../../services/sql');
async function getEventLog() {
await deleteOld();
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 = {
getEventLog
};

View File

@ -3,7 +3,7 @@
const build = require('./build');
const packageJson = require('../../package');
const APP_DB_VERSION = 95;
const APP_DB_VERSION = 96;
module.exports = {
appVersion: packageJson.version,

View File

@ -1,5 +1,6 @@
const sql = require('./sql');
const dateUtils = require('./date_utils');
const utils = require('./utils');
const log = require('./log');
async function addEvent(comment) {
@ -8,9 +9,10 @@ async function addEvent(comment) {
async function addNoteEvent(noteId, comment) {
await sql.insert('event_log', {
noteId : noteId,
comment: comment,
dateCreated: dateUtils.nowDate()
eventId: utils.newEntityId(),
noteId : noteId,
comment: comment,
dateCreated: dateUtils.nowDate()
});
log.info("Event log for " + noteId + ": " + comment);

View File

@ -207,13 +207,12 @@ const primaryKeys = {
"notes": "noteId",
"branches": "branchId",
"note_revisions": "noteRevisionId",
"option": "name",
"recent_notes": "branchId",
"images": "imageId",
"note_images": "noteImageId",
"labels": "labelId",
"api_tokens": "apiTokenId",
"options": "name"
"options": "optionId"
};
async function getEntityRow(entityName, entityId) {