60 lines
2.1 KiB
SQL
60 lines
2.1 KiB
SQL
-- Remember to increment DB_VERSION
|
|
-- in database.py on changes to this file
|
|
|
|
CREATE TABLE rules (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
source INTEGER, -- The rule this one is based on
|
|
updated INTEGER, -- If the row was updated during last data import (0: No, 1: Yes)
|
|
first_party INTEGER, -- 1: this blocks a first party for sure, 0: maybe
|
|
refs INTEGER, -- Number of entries issued from this one
|
|
level INTEGER, -- Level of recursion to the root source rule (used for source priority)
|
|
FOREIGN KEY (source) REFERENCES rules(id) ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX rules_source ON rules (source); -- for references recounting
|
|
CREATE INDEX rules_updated ON rules (updated); -- for pruning
|
|
CREATE INDEX rules_level_firstparty ON rules (level, first_party); -- for counting rules
|
|
|
|
CREATE TABLE asn (
|
|
val INTEGER PRIMARY KEY,
|
|
entry INTEGER,
|
|
FOREIGN KEY (entry) REFERENCES rules(id) ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX asn_entry ON asn (entry); -- for explainations
|
|
|
|
CREATE TABLE hostname (
|
|
val TEXT PRIMARY KEY, -- rev'd, ends with a dot (for consistency with zone)
|
|
entry INTEGER,
|
|
FOREIGN KEY (entry) REFERENCES rules(id) ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX hostname_entry ON hostname (entry); -- for explainations
|
|
|
|
CREATE TABLE zone (
|
|
val TEXT PRIMARY KEY, -- rev'd, ends with a dot (for easier matching)
|
|
entry INTEGER,
|
|
FOREIGN KEY (entry) REFERENCES rules(id) ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX zone_entry ON zone (entry); -- for explainations
|
|
|
|
CREATE TABLE ip4address (
|
|
val INTEGER PRIMARY KEY,
|
|
entry INTEGER,
|
|
FOREIGN KEY (entry) REFERENCES rules(id) ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX ip4address_entry ON ip4address (entry); -- for explainations
|
|
|
|
CREATE TABLE ip4network (
|
|
-- val TEXT PRIMARY KEY,
|
|
mini INTEGER,
|
|
maxi INTEGER,
|
|
entry INTEGER,
|
|
FOREIGN KEY (entry) REFERENCES rules(id) ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX ip4network_minmax ON ip4network (mini, maxi);
|
|
CREATE INDEX ip4network_entry ON ip4network (entry); -- for explainations
|
|
|
|
-- Store various things
|
|
CREATE TABLE meta (
|
|
key TEXT PRIMARY KEY,
|
|
value integer
|
|
);
|