Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Fix the trigger for node paths in desktop

Hakan Shehu42ffc0509bd6
diff --git a/apps/desktop/src/main/data/workspace/migrations.ts b/apps/desktop/src/main/data/workspace/migrations.ts
index e4d4b45a..98418c66 100644
--- a/apps/desktop/src/main/data/workspace/migrations.ts
+++ b/apps/desktop/src/main/data/workspace/migrations.ts
@@ -141,6 +141,10 @@ const createNodePathsTable: Migration = {
AFTER INSERT ON nodes
FOR EACH ROW
BEGIN
+ -- Insert direct path from the new node to itself
+ INSERT INTO node_paths (ancestor_id, descendant_id, level)
+ VALUES (NEW.id, NEW.id, 0);
+
-- Insert paths from ancestors to the new node
INSERT INTO node_paths (ancestor_id, descendant_id, level)
SELECT ancestor_id, NEW.id, level + 1
@@ -153,7 +157,7 @@ const createNodePathsTable: Migration = {
CREATE TRIGGER trg_update_node_path
AFTER UPDATE ON nodes
FOR EACH ROW
- WHEN OLD.parent_id IS DISTINCT FROM NEW.parent_id
+ WHEN OLD.parent_id <> NEW.parent_id
BEGIN
-- Delete old paths involving the updated node
DELETE FROM node_paths