aboutsummaryrefslogtreecommitdiff
path: root/setup.sql
diff options
context:
space:
mode:
Diffstat (limited to 'setup.sql')
-rw-r--r--setup.sql7
1 files changed, 7 insertions, 0 deletions
diff --git a/setup.sql b/setup.sql
index d5d8ce2..7b6732e 100644
--- a/setup.sql
+++ b/setup.sql
@@ -18,3 +18,10 @@ CREATE TABLE pixels (
FOREIGN KEY(image_id) REFERENCES images(id),
UNIQUE(image_id, x, y)
);
+
+CREATE TRIGGER delete_pixels_when_image_deleted
+AFTER DELETE ON images
+WHEN (SELECT COUNT(*) FROM images WHERE id = OLD.id) = 0
+BEGIN
+ DELETE FROM pixels WHERE image_id = OLD.id;
+END;