From 3f3ba519ae3c3346945928b21ab36f7238e5387e Mon Sep 17 00:00:00 2001
From: Wojtek Kosior <koszko@koszko.org>
Date: Thu, 11 Aug 2022 09:39:19 +0200
Subject: save computed payloads into sqlite db

---
 src/hydrilla/proxy/tables.sql | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

(limited to 'src/hydrilla/proxy/tables.sql')

diff --git a/src/hydrilla/proxy/tables.sql b/src/hydrilla/proxy/tables.sql
index 53539a7..25493d3 100644
--- a/src/hydrilla/proxy/tables.sql
+++ b/src/hydrilla/proxy/tables.sql
@@ -141,10 +141,6 @@ CREATE TABLE item_versions(
         version             VARCHAR NOT NULL,
 	repo_iteration_id   INTEGER NOT NULL,
 	definition          TEXT    NOT NULL,
-	-- What privileges should be granted on pages where this
-	-- resource/mapping is used.
-	eval_allowed        BOOLEAN NOT NULL,
-        cors_bypass_allowed BOOLEAN NOT NULL,
 
         UNIQUE (item_id, version, repo_iteration_id),
 	-- Allow foreign key from "mapping_statuses".
@@ -157,15 +153,19 @@ CREATE TABLE item_versions(
 );
 
 CREATE TABLE payloads(
-        payload_id      INTEGER PRIMARY KEY,
+        payload_id          INTEGER PRIMARY KEY,
 
-        mapping_item_id INTEGER NOT NULL,
-        pattern         VARCHAR NOT NULL,
+        mapping_item_id     INTEGER NOT NULL,
+        pattern             VARCHAR NOT NULL,
+	-- What privileges should be granted on pages where this
+	-- resource/mapping is used.
+	eval_allowed        BOOLEAN NOT NULL,
+        cors_bypass_allowed BOOLEAN NOT NULL,
 
         UNIQUE (mapping_item_id, pattern),
 
 	FOREIGN KEY (mapping_item_id)
-                REFERENCES item_versions (versioned_item_id)
+                REFERENCES item_versions (item_version_id)
 		ON DELETE CASCADE
 );
 
@@ -179,9 +179,11 @@ CREATE TABLE resolved_depended_resources(
         PRIMARY KEY (payload_id, resource_item_id),
 
         FOREIGN KEY (payload_id)
-                REFERENCES payloads (payload_id),
+                REFERENCES payloads (payload_id)
+		ON DELETE CASCADE,
         FOREIGN KEY (resource_item_id)
                 REFERENCES item_versions (item_version_id)
+		ON DELETE CASCADE
 ) WITHOUT ROWID;
 
 -- CREATE TABLE resolved_required_mappings(
-- 
cgit v1.2.3

