mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 23:08:07 +00:00
Unify the two group tables into a single "groups" table. This allows managing adlists and domains together.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
87c115fc86
commit
94d83dbb2d
@ -1,6 +1,6 @@
|
|||||||
PRAGMA FOREIGN_KEYS=ON;
|
PRAGMA FOREIGN_KEYS=ON;
|
||||||
|
|
||||||
CREATE TABLE domain_groups
|
CREATE TABLE groups
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
enabled BOOLEAN NOT NULL DEFAULT 1,
|
enabled BOOLEAN NOT NULL DEFAULT 1,
|
||||||
@ -20,7 +20,7 @@ CREATE TABLE whitelist
|
|||||||
CREATE TABLE whitelist_by_group
|
CREATE TABLE whitelist_by_group
|
||||||
(
|
(
|
||||||
whitelist_id INTEGER NOT NULL REFERENCES whitelist (id),
|
whitelist_id INTEGER NOT NULL REFERENCES whitelist (id),
|
||||||
group_id INTEGER NOT NULL REFERENCES domain_groups (id),
|
group_id INTEGER NOT NULL REFERENCES groups (id),
|
||||||
PRIMARY KEY (whitelist_id, group_id)
|
PRIMARY KEY (whitelist_id, group_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ CREATE TABLE blacklist
|
|||||||
CREATE TABLE blacklist_by_group
|
CREATE TABLE blacklist_by_group
|
||||||
(
|
(
|
||||||
blacklist_id INTEGER NOT NULL REFERENCES blacklist (id),
|
blacklist_id INTEGER NOT NULL REFERENCES blacklist (id),
|
||||||
group_id INTEGER NOT NULL REFERENCES domain_groups (id),
|
group_id INTEGER NOT NULL REFERENCES groups (id),
|
||||||
PRIMARY KEY (blacklist_id, group_id)
|
PRIMARY KEY (blacklist_id, group_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -54,17 +54,10 @@ CREATE TABLE regex
|
|||||||
CREATE TABLE regex_by_group
|
CREATE TABLE regex_by_group
|
||||||
(
|
(
|
||||||
regex_id INTEGER NOT NULL REFERENCES regex (id),
|
regex_id INTEGER NOT NULL REFERENCES regex (id),
|
||||||
group_id INTEGER NOT NULL REFERENCES domain_groups (id),
|
group_id INTEGER NOT NULL REFERENCES groups (id),
|
||||||
PRIMARY KEY (regex_id, group_id)
|
PRIMARY KEY (regex_id, group_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE adlists_groups
|
|
||||||
(
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
enabled BOOLEAN NOT NULL DEFAULT 1,
|
|
||||||
description TEXT
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE adlists
|
CREATE TABLE adlists
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
@ -78,7 +71,7 @@ CREATE TABLE adlists
|
|||||||
CREATE TABLE adlists_by_group
|
CREATE TABLE adlists_by_group
|
||||||
(
|
(
|
||||||
adlists_id INTEGER NOT NULL REFERENCES adlists (id),
|
adlists_id INTEGER NOT NULL REFERENCES adlists (id),
|
||||||
group_id INTEGER NOT NULL REFERENCES adlists_groups (id),
|
group_id INTEGER NOT NULL REFERENCES groups (id),
|
||||||
PRIMARY KEY (adlists_id, group_id)
|
PRIMARY KEY (adlists_id, group_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -101,8 +94,8 @@ CREATE VIEW vw_gravity AS SELECT domain
|
|||||||
CREATE VIEW vw_whitelist AS SELECT domain
|
CREATE VIEW vw_whitelist AS SELECT domain
|
||||||
FROM whitelist
|
FROM whitelist
|
||||||
LEFT JOIN whitelist_by_group ON whitelist_by_group.whitelist_id = whitelist.id
|
LEFT JOIN whitelist_by_group ON whitelist_by_group.whitelist_id = whitelist.id
|
||||||
LEFT JOIN domain_groups ON domain_groups.id = whitelist_by_group.group_id
|
LEFT JOIN groups ON groups.id = whitelist_by_group.group_id
|
||||||
WHERE whitelist.enabled = 1 AND domain_groups.enabled IS NULL OR domain_groups.enabled == 1
|
WHERE whitelist.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1
|
||||||
ORDER BY whitelist.id;
|
ORDER BY whitelist.id;
|
||||||
|
|
||||||
CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist
|
CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist
|
||||||
@ -113,8 +106,8 @@ CREATE TRIGGER tr_whitelist_update AFTER UPDATE ON whitelist
|
|||||||
CREATE VIEW vw_blacklist AS SELECT domain
|
CREATE VIEW vw_blacklist AS SELECT domain
|
||||||
FROM blacklist
|
FROM blacklist
|
||||||
LEFT JOIN blacklist_by_group ON blacklist_by_group.blacklist_id = blacklist.id
|
LEFT JOIN blacklist_by_group ON blacklist_by_group.blacklist_id = blacklist.id
|
||||||
LEFT JOIN domain_groups ON domain_groups.id = blacklist_by_group.group_id
|
LEFT JOIN groups ON groups.id = blacklist_by_group.group_id
|
||||||
WHERE blacklist.enabled = 1 AND domain_groups.enabled IS NULL OR domain_groups.enabled == 1
|
WHERE blacklist.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1
|
||||||
ORDER BY blacklist.id;
|
ORDER BY blacklist.id;
|
||||||
|
|
||||||
CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist
|
CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist
|
||||||
@ -125,8 +118,8 @@ CREATE TRIGGER tr_blacklist_update AFTER UPDATE ON blacklist
|
|||||||
CREATE VIEW vw_regex AS SELECT domain
|
CREATE VIEW vw_regex AS SELECT domain
|
||||||
FROM regex
|
FROM regex
|
||||||
LEFT JOIN regex_by_group ON regex_by_group.regex_id = regex.id
|
LEFT JOIN regex_by_group ON regex_by_group.regex_id = regex.id
|
||||||
LEFT JOIN domain_groups ON domain_groups.id = regex_by_group.group_id
|
LEFT JOIN groups ON groups.id = regex_by_group.group_id
|
||||||
WHERE regex.enabled = 1 AND domain_groups.enabled IS NULL OR domain_groups.enabled == 1
|
WHERE regex.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1
|
||||||
ORDER BY regex.id;
|
ORDER BY regex.id;
|
||||||
|
|
||||||
CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex
|
CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex
|
||||||
@ -137,8 +130,8 @@ CREATE TRIGGER tr_regex_update AFTER UPDATE ON regex
|
|||||||
CREATE VIEW vw_adlists AS SELECT address
|
CREATE VIEW vw_adlists AS SELECT address
|
||||||
FROM adlists
|
FROM adlists
|
||||||
LEFT JOIN adlists_by_group ON adlists_by_group.adlists_id = adlists.id
|
LEFT JOIN adlists_by_group ON adlists_by_group.adlists_id = adlists.id
|
||||||
LEFT JOIN adlists_groups ON adlists_groups.id = adlists_by_group.group_id
|
LEFT JOIN groups ON groups.id = adlists_by_group.group_id
|
||||||
WHERE adlists.enabled = 1 AND adlists_groups.enabled IS NULL OR adlists_groups.enabled == 1
|
WHERE adlists.enabled = 1 AND groups.enabled IS NULL OR groups.enabled == 1
|
||||||
ORDER BY adlists.id;
|
ORDER BY adlists.id;
|
||||||
|
|
||||||
CREATE TRIGGER tr_adlists_update AFTER UPDATE ON adlists
|
CREATE TRIGGER tr_adlists_update AFTER UPDATE ON adlists
|
||||||
|
Loading…
Reference in New Issue
Block a user