From 8e6ac728ed8786dca03c2bd84d90885a7cbb79cd Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Sat, 28 Dec 2024 03:56:01 -0500 Subject: [PATCH] setup foreign key constraints --- nomen/db.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/nomen/db.py b/nomen/db.py index d200e14..d28c3c9 100644 --- a/nomen/db.py +++ b/nomen/db.py @@ -13,11 +13,12 @@ schema = """ PRAGMA user_version = 1; PRAGMA main.synchronous = NORMAL; +PRAGMA foreign_keys = ON; CREATE TABLE keywords ( guild_id INTEGER NOT NULL, keyword TEXT NOT NULL, - user_id INTEGER NOT NULL, + user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, regex INTEGER NOT NULL DEFAULT 0 CHECK(regex IN (0, 1)), count INTEGER NOT NULL DEFAULT 0 ); @@ -38,17 +39,21 @@ CREATE TABLE users ( WITHOUT ROWID; CREATE TABLE user_ignores ( - user_id INTEGER NOT NULL, + user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, guild_id INTEGER NOT NULL, target INTEGER NOT NULL, PRIMARY KEY (user_id, guild_id, target) ); CREATE TABLE user_blocks ( - user_id INTEGER NOT NULL, + user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE, target INTEGER NOT NULL, PRIMARY KEY (user_id, target) ); + +CREATE INDEX keywords_index ON keywords(user_id); +CREATE INDEX user_ignores_index ON user_ignores(user_id); +CREATE INDEX user_blocks_index ON user_blocks(user_id); """