mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
more cleanup of labels and relations from backend, dropping tables from db
This commit is contained in:
parent
1c0fd243d1
commit
f1240c26bf
4
db/migrations/0111__cleanup_labels_and_relations.sql
Normal file
4
db/migrations/0111__cleanup_labels_and_relations.sql
Normal file
@ -0,0 +1,4 @@
|
||||
DROP TABLE relations;
|
||||
DROP TABLE labels;
|
||||
|
||||
DELETE FROM sync WHERE entityName = 'relations' OR entityName = 'labels';
|
@ -4,8 +4,6 @@ const Image = require('../entities/image');
|
||||
const NoteImage = require('../entities/note_image');
|
||||
const Branch = require('../entities/branch');
|
||||
const Attribute = require('../entities/attribute');
|
||||
const Label = require('../entities/label');
|
||||
const Relation = require('../entities/relation');
|
||||
const RecentNote = require('../entities/recent_note');
|
||||
const ApiToken = require('../entities/api_token');
|
||||
const Option = require('../entities/option');
|
||||
@ -17,12 +15,6 @@ function createEntityFromRow(row) {
|
||||
if (row.attributeId) {
|
||||
entity = new Attribute(row);
|
||||
}
|
||||
else if (row.labelId) {
|
||||
entity = new Label(row);
|
||||
}
|
||||
else if (row.relationId) {
|
||||
entity = new Relation(row);
|
||||
}
|
||||
else if (row.noteRevisionId) {
|
||||
entity = new NoteRevision(row);
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const Entity = require('./entity');
|
||||
const repository = require('../services/repository');
|
||||
const dateUtils = require('../services/date_utils');
|
||||
const sql = require('../services/sql');
|
||||
|
||||
class Label extends Entity {
|
||||
static get tableName() { return "labels"; }
|
||||
static get primaryKeyName() { return "labelId"; }
|
||||
static get hashedProperties() { return ["labelId", "noteId", "name", "value", "dateModified", "dateCreated"]; }
|
||||
|
||||
async getNote() {
|
||||
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||
}
|
||||
|
||||
async beforeSaving() {
|
||||
if (!this.value) {
|
||||
// null value isn't allowed
|
||||
this.value = "";
|
||||
}
|
||||
|
||||
if (this.position === undefined) {
|
||||
this.position = 1 + await sql.getValue(`SELECT COALESCE(MAX(position), 0) FROM labels WHERE noteId = ?`, [this.noteId]);
|
||||
}
|
||||
|
||||
if (!this.isDeleted) {
|
||||
this.isDeleted = false;
|
||||
}
|
||||
|
||||
if (!this.dateCreated) {
|
||||
this.dateCreated = dateUtils.nowDate();
|
||||
}
|
||||
|
||||
this.dateModified = dateUtils.nowDate();
|
||||
|
||||
super.beforeSaving();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Label;
|
@ -1,44 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const Entity = require('./entity');
|
||||
const repository = require('../services/repository');
|
||||
const dateUtils = require('../services/date_utils');
|
||||
const sql = require('../services/sql');
|
||||
|
||||
class Relation extends Entity {
|
||||
static get tableName() { return "relations"; }
|
||||
static get primaryKeyName() { return "relationId"; }
|
||||
static get hashedProperties() { return ["relationId", "sourceNoteId", "name", "targetNoteId", "isInheritable", "dateModified", "dateCreated"]; }
|
||||
|
||||
async getSourceNote() {
|
||||
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.sourceNoteId]);
|
||||
}
|
||||
|
||||
async getTargetNote() {
|
||||
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.targetNoteId]);
|
||||
}
|
||||
|
||||
async beforeSaving() {
|
||||
if (this.position === undefined) {
|
||||
this.position = 1 + await sql.getValue(`SELECT COALESCE(MAX(position), 0) FROM relations WHERE sourceNoteId = ?`, [this.sourceNoteId]);
|
||||
}
|
||||
|
||||
if (!this.isInheritable) {
|
||||
this.isInheritable = false;
|
||||
}
|
||||
|
||||
if (!this.isDeleted) {
|
||||
this.isDeleted = false;
|
||||
}
|
||||
|
||||
if (!this.dateCreated) {
|
||||
this.dateCreated = dateUtils.nowDate();
|
||||
}
|
||||
|
||||
this.dateModified = dateUtils.nowDate();
|
||||
|
||||
super.beforeSaving();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Relation;
|
@ -3,7 +3,7 @@
|
||||
const build = require('./build');
|
||||
const packageJson = require('../../package');
|
||||
|
||||
const APP_DB_VERSION = 110;
|
||||
const APP_DB_VERSION = 111;
|
||||
const SYNC_VERSION = 1;
|
||||
|
||||
module.exports = {
|
||||
|
@ -223,7 +223,7 @@ async function runAllChecks() {
|
||||
await runSyncRowChecks("recent_notes", "branchId", errorList);
|
||||
await runSyncRowChecks("images", "imageId", errorList);
|
||||
await runSyncRowChecks("note_images", "noteImageId", errorList);
|
||||
await runSyncRowChecks("labels", "labelId", errorList);
|
||||
await runSyncRowChecks("attributes", "attributeId", errorList);
|
||||
await runSyncRowChecks("api_tokens", "apiTokenId", errorList);
|
||||
|
||||
if (errorList.length === 0) {
|
||||
|
@ -9,8 +9,8 @@ const ApiToken = require('../entities/api_token');
|
||||
const Branch = require('../entities/branch');
|
||||
const Image = require('../entities/image');
|
||||
const Note = require('../entities/note');
|
||||
const Attribute = require('../entities/attribute');
|
||||
const NoteImage = require('../entities/note_image');
|
||||
const Label = require('../entities/label');
|
||||
const NoteRevision = require('../entities/note_revision');
|
||||
const RecentNote = require('../entities/recent_note');
|
||||
const Option = require('../entities/option');
|
||||
@ -40,7 +40,7 @@ async function getHashes() {
|
||||
options: await getHash(Option, "isSynced = 1"),
|
||||
images: await getHash(Image),
|
||||
note_images: await getHash(NoteImage),
|
||||
labels: await getHash(Label),
|
||||
attributes: await getHash(Attribute),
|
||||
api_tokens: await getHash(ApiToken)
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,7 @@ async function load() {
|
||||
childParentToBranchId[`${rel.noteId}-${rel.parentNoteId}`] = rel.branchId;
|
||||
}
|
||||
|
||||
const hiddenLabels = await sql.getColumn(`SELECT noteId FROM labels WHERE isDeleted = 0 AND name = 'archived'`);
|
||||
const hiddenLabels = await sql.getColumn(`SELECT noteId FROM attributes WHERE type = 'label' AND isDeleted = 0 AND name = 'archived'`);
|
||||
|
||||
for (const noteId of hiddenLabels) {
|
||||
archived[noteId] = true;
|
||||
@ -265,19 +265,19 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entityId
|
||||
childParentToBranchId[branch.noteId + '-' + branch.parentNoteId] = branch.branchId;
|
||||
}
|
||||
}
|
||||
else if (entityName === 'labels') {
|
||||
const label = await repository.getLabel(entityId);
|
||||
else if (entityName === 'attributes') {
|
||||
const attribute = await repository.getAttribute(entityId);
|
||||
|
||||
if (label.name === 'archived') {
|
||||
if (attribute.type === 'label' && attribute.name === 'archived') {
|
||||
// we're not using label object directly, since there might be other non-deleted archived label
|
||||
const hideLabel = await repository.getEntity(`SELECT * FROM labels WHERE isDeleted = 0
|
||||
AND name = 'archived' AND noteId = ?`, [label.noteId]);
|
||||
const hideLabel = await repository.getEntity(`SELECT * FROM attributes WHERE isDeleted = 0 AND type = 'label'
|
||||
AND name = 'archived' AND noteId = ?`, [attribute.noteId]);
|
||||
|
||||
if (hideLabel) {
|
||||
archived[label.noteId] = true;
|
||||
archived[attribute.noteId] = true;
|
||||
}
|
||||
else {
|
||||
delete archived[label.noteId];
|
||||
delete archived[attribute.noteId];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user