Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
more cleanup of labels and relations from backend, dropping tables from db
azivnerf1240c26bf44
diff --git a/db/migrations/0111__cleanup_labels_and_relations.sql b/db/migrations/0111__cleanup_labels_and_relations.sqlnew file mode 100644index 0000000000..795d883933--- /dev/null+++ b/db/migrations/0111__cleanup_labels_and_relations.sql@@ -0,0 +1,4 @@+DROP TABLE relations;+DROP TABLE labels;++DELETE FROM sync WHERE entityName = 'relations' OR entityName = 'labels';\ No newline at end of filediff --git a/src/entities/entity_constructor.js b/src/entities/entity_constructor.jsindex 78022dbc48..fb73cd4c97 100644--- a/src/entities/entity_constructor.js+++ b/src/entities/entity_constructor.js@@ -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);}diff --git a/src/entities/label.js b/src/entities/label.jsdeleted file mode 100644index fd10b38595..0000000000--- a/src/entities/label.js+++ /dev/null@@ -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;\ No newline at end of filediff --git a/src/entities/relation.js b/src/entities/relation.jsdeleted file mode 100644index 76e938c613..0000000000--- a/src/entities/relation.js+++ /dev/null@@ -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;\ No newline at end of filediff --git a/src/services/app_info.js b/src/services/app_info.jsindex 66ab29459a..22383c70a7 100644--- a/src/services/app_info.js+++ b/src/services/app_info.js@@ -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 = {diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex d326aa972b..7e65d2d729 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -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) {diff --git a/src/services/content_hash.js b/src/services/content_hash.jsindex 9cb568a895..903bcbcf49 100644--- a/src/services/content_hash.js+++ b/src/services/content_hash.js@@ -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)};diff --git a/src/services/note_cache.js b/src/services/note_cache.jsindex c43d97454a..5b5717b1a0 100644--- a/src/services/note_cache.js+++ b/src/services/note_cache.js@@ -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, entityIdchildParentToBranchId[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];}}}