setup foreign key constraints

This commit is contained in:
Infinidoge 2024-12-28 03:56:01 -05:00
parent 38e41dc1b5
commit 8e6ac728ed
Signed by: Infinidoge
SSH key fingerprint: SHA256:GT2StvPQMMfFHyiiFJymQxfTG/z6EWLJ6NWItf5K5sA

View file

@ -13,11 +13,12 @@ schema = """
PRAGMA user_version = 1; PRAGMA user_version = 1;
PRAGMA main.synchronous = NORMAL; PRAGMA main.synchronous = NORMAL;
PRAGMA foreign_keys = ON;
CREATE TABLE keywords ( CREATE TABLE keywords (
guild_id INTEGER NOT NULL, guild_id INTEGER NOT NULL,
keyword TEXT 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)), regex INTEGER NOT NULL DEFAULT 0 CHECK(regex IN (0, 1)),
count INTEGER NOT NULL DEFAULT 0 count INTEGER NOT NULL DEFAULT 0
); );
@ -38,17 +39,21 @@ CREATE TABLE users (
WITHOUT ROWID; WITHOUT ROWID;
CREATE TABLE user_ignores ( CREATE TABLE user_ignores (
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE,
guild_id INTEGER NOT NULL, guild_id INTEGER NOT NULL,
target INTEGER NOT NULL, target INTEGER NOT NULL,
PRIMARY KEY (user_id, guild_id, target) PRIMARY KEY (user_id, guild_id, target)
); );
CREATE TABLE user_blocks ( CREATE TABLE user_blocks (
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE,
target INTEGER NOT NULL, target INTEGER NOT NULL,
PRIMARY KEY (user_id, target) 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);
""" """