aboutsummaryrefslogtreecommitdiff
path: root/initialize.sql
diff options
context:
space:
mode:
Diffstat (limited to 'initialize.sql')
-rw-r--r--initialize.sql17
1 files changed, 16 insertions, 1 deletions
diff --git a/initialize.sql b/initialize.sql
index c230f18..60b50f0 100644
--- a/initialize.sql
+++ b/initialize.sql
@@ -47,13 +47,28 @@ END;
--
--- TODO: Add a trigger to delete from here when a node for the sha1 is added.
CREATE TABLE IF NOT EXISTS orphan(
sha1 TEXT NOT NULL REFERENCES image(sha1)
path TEXT NOT NULL,
PRIMARY KEY (sha1)
) STRICT;
+-- Renaming/moving a file can result either in a (ref, unref) or a (unref, ref)
+-- sequence during sync, and I want to get at the same result.
+CREATE TRIGGER IF NOT EXISTS node__sha1__deorphan_insert
+AFTER INSERT ON node
+WHEN NEW.sha1 IS NOT NULL
+BEGIN
+ DELETE FROM orphan WHERE sha1 = NEW.sha1;
+END;
+
+CREATE TRIGGER IF NOT EXISTS node__sha1__deorphan_update
+AFTER UPDATE OF sha1 ON node
+WHEN NEW.sha1 IS NOT NULL
+BEGIN
+ DELETE FROM orphan WHERE sha1 = NEW.sha1;
+END;
+
--
CREATE TABLE IF NOT EXISTS tag_space(