From ed4b84d2ca7e5b13d010effefb8ae676d084124a Mon Sep 17 00:00:00 2001
From: Akshay Nair <phenax5@gmail.com>
Date: Wed, 3 Jun 2026 23:57:21 +0530
Subject: Refactor image.sh to handle png + cleanup sql

---
 setup.sql | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

(limited to 'setup.sql')

diff --git a/setup.sql b/setup.sql
index 7b6732e..3a80a8c 100644
--- a/setup.sql
+++ b/setup.sql
@@ -8,20 +8,19 @@ CREATE TABLE images (
 );
 
 CREATE TABLE pixels (
-  id INTEGER PRIMARY KEY AUTOINCREMENT,
+  id INTEGER PRIMARY KEY,
   image_id TEXT NOT NULL,
   x INTEGER NOT NULL,
   y INTEGER NOT NULL,
   r INTEGER NOT NULL CHECK(r >= 0 AND r <= 255),
   g INTEGER NOT NULL CHECK(g >= 0 AND g <= 255),
   b INTEGER NOT NULL CHECK(b >= 0 AND b <= 255),
-  FOREIGN KEY(image_id) REFERENCES images(id),
+  -- FOREIGN KEY(image_id) REFERENCES images(id) ON DELETE CASCADE,
   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
+CREATE TRIGGER delete_pixels_when_image_reinserted_because_i_said_so_and_to_make_rerunning_easier
+BEFORE INSERT ON images
 BEGIN
-  DELETE FROM pixels WHERE image_id = OLD.id;
+  DELETE FROM pixels WHERE image_id = NEW.id;
 END;
-- 
cgit v1.3.1

