2019-06-16 14:50:51 +00:00
|
|
|
PRAGMA FOREIGN_KEYS=ON;
|
|
|
|
|
2019-06-30 18:03:22 +00:00
|
|
|
CREATE TABLE "group"
|
2019-06-16 14:50:51 +00:00
|
|
|
(
|
2019-06-30 16:58:47 +00:00
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
enabled BOOLEAN NOT NULL DEFAULT 1,
|
2019-06-30 21:06:15 +00:00
|
|
|
name TEXT NOT NULL,
|
2019-06-30 16:58:47 +00:00
|
|
|
description TEXT
|
2019-06-16 14:50:51 +00:00
|
|
|
);
|
|
|
|
|
2019-05-01 15:57:23 +00:00
|
|
|
CREATE TABLE whitelist
|
|
|
|
(
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
domain TEXT UNIQUE NOT NULL,
|
|
|
|
enabled BOOLEAN NOT NULL DEFAULT 1,
|
|
|
|
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
|
|
|
date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
2019-06-30 16:58:47 +00:00
|
|
|
comment TEXT
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE whitelist_by_group
|
|
|
|
(
|
|
|
|
whitelist_id INTEGER NOT NULL REFERENCES whitelist (id),
|
2019-06-30 18:03:22 +00:00
|
|
|
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
2019-06-30 16:58:47 +00:00
|
|
|
PRIMARY KEY (whitelist_id, group_id)
|
2019-05-01 15:57:23 +00:00
|
|
|
);
|
2019-06-30 16:58:47 +00:00
|
|
|
|
2019-05-01 15:57:23 +00:00
|
|
|
CREATE TABLE blacklist
|
|
|
|
(
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
domain TEXT UNIQUE NOT NULL,
|
|
|
|
enabled BOOLEAN NOT NULL DEFAULT 1,
|
|
|
|
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
|
|
|
date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
2019-06-30 16:58:47 +00:00
|
|
|
comment TEXT
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE blacklist_by_group
|
|
|
|
(
|
|
|
|
blacklist_id INTEGER NOT NULL REFERENCES blacklist (id),
|
2019-06-30 18:03:22 +00:00
|
|
|
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
2019-06-30 16:58:47 +00:00
|
|
|
PRIMARY KEY (blacklist_id, group_id)
|
2019-05-01 15:57:23 +00:00
|
|
|
);
|
2019-06-30 16:58:47 +00:00
|
|
|
|
2019-05-01 15:57:23 +00:00
|
|
|
CREATE TABLE regex
|
|
|
|
(
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
domain TEXT UNIQUE NOT NULL,
|
|
|
|
enabled BOOLEAN NOT NULL DEFAULT 1,
|
|
|
|
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
|
|
|
date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
2019-06-30 16:58:47 +00:00
|
|
|
comment TEXT
|
2019-05-01 15:57:23 +00:00
|
|
|
);
|
2019-06-16 15:05:33 +00:00
|
|
|
|
2019-06-30 16:58:47 +00:00
|
|
|
CREATE TABLE regex_by_group
|
2019-06-16 15:05:33 +00:00
|
|
|
(
|
2019-06-30 16:58:47 +00:00
|
|
|
regex_id INTEGER NOT NULL REFERENCES regex (id),
|
2019-06-30 18:03:22 +00:00
|
|
|
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
2019-06-30 16:58:47 +00:00
|
|
|
PRIMARY KEY (regex_id, group_id)
|
|
|
|
);
|
|
|
|
|
2019-06-30 21:21:10 +00:00
|
|
|
CREATE TABLE adlist
|
2019-05-01 15:57:23 +00:00
|
|
|
(
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
address TEXT UNIQUE NOT NULL,
|
|
|
|
enabled BOOLEAN NOT NULL DEFAULT 1,
|
|
|
|
date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
|
|
|
date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
|
2019-06-30 16:58:47 +00:00
|
|
|
comment TEXT
|
2019-05-01 15:57:23 +00:00
|
|
|
);
|
2019-06-30 16:58:47 +00:00
|
|
|
|
2019-06-30 21:21:10 +00:00
|
|
|
CREATE TABLE adlist_by_group
|
2019-06-30 16:58:47 +00:00
|
|
|
(
|
2019-06-30 21:21:10 +00:00
|
|
|
adlist_id INTEGER NOT NULL REFERENCES adlist (id),
|
2019-06-30 18:03:22 +00:00
|
|
|
group_id INTEGER NOT NULL REFERENCES "group" (id),
|
2019-06-30 21:21:10 +00:00
|
|
|
PRIMARY KEY (adlist_id, group_id)
|
2019-06-30 16:58:47 +00:00
|
|
|
);
|
|
|
|
|
2019-05-01 15:57:23 +00:00
|
|
|
CREATE TABLE gravity
|
|
|
|
(
|
2019-05-01 20:08:30 +00:00
|
|
|
domain TEXT PRIMARY KEY
|
2019-05-01 15:57:23 +00:00
|
|
|
);
|
|
|
|
CREATE TABLE info
|
|
|
|
(
|
2019-05-01 16:03:35 +00:00
|
|
|
property TEXT PRIMARY KEY,
|
2019-05-01 15:57:23 +00:00
|
|
|
value TEXT NOT NULL
|
|
|
|
);
|
2019-02-06 17:57:48 +00:00
|
|
|
|
|
|
|
INSERT INTO info VALUES("version","1");
|
2019-02-05 18:05:11 +00:00
|
|
|
|
2019-06-30 16:58:47 +00:00
|
|
|
CREATE VIEW vw_gravity AS SELECT domain
|
|
|
|
FROM gravity
|
|
|
|
WHERE domain NOT IN (SELECT domain from vw_whitelist);
|
2019-02-05 18:05:11 +00:00
|
|
|
|
2019-06-30 16:58:47 +00:00
|
|
|
CREATE VIEW vw_whitelist AS SELECT domain
|
|
|
|
FROM whitelist
|
|
|
|
LEFT JOIN whitelist_by_group ON whitelist_by_group.whitelist_id = whitelist.id
|
2019-06-30 18:03:22 +00:00
|
|
|
LEFT JOIN "group" ON "group".id = whitelist_by_group.group_id
|
2019-06-30 21:07:03 +00:00
|
|
|
WHERE whitelist.enabled = 1 AND (whitelist_by_group.group_id IS NULL OR "group".enabled = 1)
|
2019-06-30 16:58:47 +00:00
|
|
|
ORDER BY whitelist.id;
|
2019-05-01 15:50:36 +00:00
|
|
|
|
2019-04-29 17:43:35 +00:00
|
|
|
CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist
|
|
|
|
BEGIN
|
|
|
|
UPDATE whitelist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain;
|
2019-05-01 14:38:41 +00:00
|
|
|
END;
|
2019-02-05 18:05:11 +00:00
|
|
|
|
2019-06-30 16:58:47 +00:00
|
|
|
CREATE VIEW vw_blacklist AS SELECT domain
|
|
|
|
FROM blacklist
|
|
|
|
LEFT JOIN blacklist_by_group ON blacklist_by_group.blacklist_id = blacklist.id
|
2019-06-30 18:03:22 +00:00
|
|
|
LEFT JOIN "group" ON "group".id = blacklist_by_group.group_id
|
2019-06-30 21:07:03 +00:00
|
|
|
WHERE blacklist.enabled = 1 AND (blacklist_by_group.group_id IS NULL OR "group".enabled = 1)
|
2019-06-30 16:58:47 +00:00
|
|
|
ORDER BY blacklist.id;
|
2019-05-01 15:50:36 +00:00
|
|
|
|
2019-04-29 17:43:35 +00:00
|
|
|
CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist
|
|
|
|
BEGIN
|
|
|
|
UPDATE blacklist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain;
|
2019-05-01 14:38:41 +00:00
|
|
|
END;
|
2019-04-28 12:42:52 +00:00
|
|
|
|
2019-06-30 16:58:47 +00:00
|
|
|
CREATE VIEW vw_regex AS SELECT domain
|
|
|
|
FROM regex
|
|
|
|
LEFT JOIN regex_by_group ON regex_by_group.regex_id = regex.id
|
2019-06-30 18:03:22 +00:00
|
|
|
LEFT JOIN "group" ON "group".id = regex_by_group.group_id
|
2019-06-30 21:07:03 +00:00
|
|
|
WHERE regex.enabled = 1 AND (regex_by_group.group_id IS NULL OR "group".enabled = 1)
|
2019-06-30 16:58:47 +00:00
|
|
|
ORDER BY regex.id;
|
2019-05-01 15:50:36 +00:00
|
|
|
|
2019-04-29 17:43:35 +00:00
|
|
|
CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex
|
|
|
|
BEGIN
|
|
|
|
UPDATE regex SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE domain = NEW.domain;
|
2019-05-01 14:38:41 +00:00
|
|
|
END;
|
2019-04-26 15:36:00 +00:00
|
|
|
|
2019-06-30 21:21:10 +00:00
|
|
|
CREATE VIEW vw_adlist AS SELECT address
|
|
|
|
FROM adlist
|
|
|
|
LEFT JOIN adlist_by_group ON adlist_by_group.adlist_id = adlist.id
|
|
|
|
LEFT JOIN "group" ON "group".id = adlist_by_group.group_id
|
|
|
|
WHERE adlist.enabled = 1 AND (adlist_by_group.group_id IS NULL OR "group".enabled = 1)
|
|
|
|
ORDER BY adlist.id;
|
2019-05-01 15:50:36 +00:00
|
|
|
|
2019-06-30 21:21:10 +00:00
|
|
|
CREATE TRIGGER tr_adlist_update AFTER UPDATE ON adlist
|
2019-04-29 17:43:35 +00:00
|
|
|
BEGIN
|
2019-06-30 21:21:10 +00:00
|
|
|
UPDATE adlist SET date_modified = (cast(strftime('%s', 'now') as int)) WHERE address = NEW.address;
|
2019-05-01 14:38:41 +00:00
|
|
|
END;
|
2019-04-29 17:43:35 +00:00
|
|
|
|