From 4776541df41b96e039d5ae485e09f537aee0a010 Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Thu, 5 Nov 2020 05:45:57 -0800 Subject: [PATCH] A little store-level constraining never hurt nobody. --- server/nm-store/src/sql/initialize_database.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/nm-store/src/sql/initialize_database.sql b/server/nm-store/src/sql/initialize_database.sql index e72adba..3ad220d 100644 --- a/server/nm-store/src/sql/initialize_database.sql +++ b/server/nm-store/src/sql/initialize_database.sql @@ -32,7 +32,8 @@ CREATE TABLE note_relationships ( kind TEXT NOT NULL, -- If either note disappears, we want all the edges to disappear as well. FOREIGN KEY (note_id) REFERENCES notes (id) ON DELETE CASCADE, - FOREIGN KEY (parent_id) REFERENCES notes (id) ON DELETE CASCADE + FOREIGN KEY (parent_id) REFERENCES notes (id) ON DELETE CASCADE, + CHECK (note_id <> parent_id) ); -- This table represents the graph of data relating notes to kastens. @@ -43,6 +44,7 @@ CREATE TABLE note_kasten_relationships ( kind TEXT NOT NULL, -- If either note disappears, we want all the edges to disappear as well. FOREIGN KEY (note_id) REFERENCES notes (id) ON DELETE CASCADE, - FOREIGN KEY (kasten_id) REFERENCES notes (id) ON DELETE CASCADE + FOREIGN KEY (kasten_id) REFERENCES notes (id) ON DELETE CASCADE, + CHECK (note_id <> kasten_id) );