From 968481312058aa58261d41cf3460b45109fec240 Mon Sep 17 00:00:00 2001
From: Zach Berwaldt <zberwaldt@tutamail.com>
Date: Sat, 16 Mar 2024 10:48:52 -0400
Subject: clean up database scripts, start readmes.

---
 db/sql/triggers.sql | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 db/sql/triggers.sql

(limited to 'db/sql/triggers.sql')

diff --git a/db/sql/triggers.sql b/db/sql/triggers.sql
new file mode 100644
index 0000000..3827642
--- /dev/null
+++ b/db/sql/triggers.sql
@@ -0,0 +1,11 @@
+CREATE TRIGGER IF NOT EXISTS enforce_size_id
+BEFORE INSERT ON Preferences
+BEGIN
+    SELECT
+        CASE
+            WHEN (
+                SELECT COUNT(*) FROM Sizes WHERE id = new.size_id
+            ) = 0
+            THEN RAISE(ABORT, 'Size does not exist')
+        END;
+END;
-- 
cgit v1.1

