setup foreign key constraints
This commit is contained in:
parent
38e41dc1b5
commit
8e6ac728ed
1 changed files with 8 additions and 3 deletions
11
nomen/db.py
11
nomen/db.py
|
@ -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);
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue