aboutsummaryrefslogtreecommitdiff
path: root/initialize.sql
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-12-21 06:19:03 +0100
committerPřemysl Eric Janouch <p@janouch.name>2023-12-21 06:19:03 +0100
commit068f6f82cfee723e6c6213ea58d05c9e9708e131 (patch)
tree9c49bde1a866299e6a54e83d28ee65771752e18f /initialize.sql
parent2011f2b198871b6acb4bbc50012b8bd6801b6a7f (diff)
downloadgallery-068f6f82cfee723e6c6213ea58d05c9e9708e131.tar.gz
gallery-068f6f82cfee723e6c6213ea58d05c9e9708e131.tar.xz
gallery-068f6f82cfee723e6c6213ea58d05c9e9708e131.zip
WIP: FS to DB sync
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(