PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
DROP TABLE IF EXISTS 'domainlist_by_group';
DROP TABLE IF EXISTS 'client_by_group';
DROP TABLE IF EXISTS 'client';
DROP TABLE IF EXISTS 'group';
DROP TABLE IF EXISTS 'domainlist';
DROP TABLE IF EXISTS 'adlist';
CREATE TABLE IF NOT EXISTS "group"
(
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    enabled BOOLEAN NOT NULL DEFAULT 1,
    name TEXT UNIQUE NOT NULL,
    date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
    date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
    description TEXT
);
INSERT INTO "group" VALUES(0,1,'Default',1647808795,1647808795,'The default group');
INSERT INTO "group" VALUES(1,1,'parental',1647813520,1669588905,'PC Test');
CREATE TABLE domainlist
(
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    type INTEGER NOT NULL DEFAULT 0,
    domain TEXT 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)),
    comment TEXT,
    UNIQUE(domain, type)
);
INSERT INTO domainlist VALUES(2,3,'porn',1,1647813704,1647813704,NULL);
INSERT INTO domainlist VALUES(4,0,'ws-goguardian.pusher.com',1,1687722407,1687722407,'Added from Query Log');
CREATE TABLE adlist
(
    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)),
    comment TEXT,
    date_updated INTEGER,
    number INTEGER NOT NULL DEFAULT 0,
    invalid_domains INTEGER NOT NULL DEFAULT 0,
    status INTEGER NOT NULL DEFAULT 0
);
INSERT INTO adlist VALUES(1,'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts',0,1728225653,1728235222,'Migrated from /etc/pihole/adlists.list',1728234445,116379,1,2);
INSERT INTO adlist VALUES(2,'https://v.firebog.net/hosts/static/w3kbl.txt',1,1728234516,1728234516,NULL,1736677982,351,0,2);
INSERT INTO adlist VALUES(3,'https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts',0,1728234528,1728234529,NULL,NULL,0,0,0);
INSERT INTO adlist VALUES(4,'https://www.github.developerdan.com/hosts/lists/ads-and-tracking-extended.txt',1,1728234540,1728234540,NULL,1736677983,429286,0,2);
INSERT INTO adlist VALUES(5,'https://raw.githubusercontent.com/hagezi/dns-blocklists/main/adblock/pro.txt',1,1728234546,1728234546,NULL,1736677985,0,0,1);
CREATE TABLE domainlist_by_group
(
    domainlist_id INTEGER NOT NULL REFERENCES domainlist (id),
    group_id INTEGER NOT NULL REFERENCES "group" (id),
    PRIMARY KEY (domainlist_id, group_id)
);
INSERT INTO domainlist_by_group(rowid,domainlist_id,group_id) VALUES(1,2,0);
INSERT INTO domainlist_by_group(rowid,domainlist_id,group_id) VALUES(2,4,0);
CREATE TABLE client
(
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    ip TEXT NOT NULL UNIQUE,
    date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
    date_modified INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)),
    comment TEXT
);
INSERT INTO client VALUES(1,'1C:BF:CE:29:15:B6',1647813479,1647813558,NULL);
INSERT INTO client VALUES(2,'6A:AB:AE:99:1D:9F',1649223413,1649223426,'Phone');
INSERT INTO client VALUES(3,'78:32:1B:FE:69:D9',1652915598,1652915598,'Ken');
INSERT INTO client VALUES(4,'2A:8F:6E:53:D2:A1',1669589189,1669589365,'My phone ');
INSERT INTO client VALUES(5,'BA:52:29:DC:DD:D7',1679597086,1679597103,NULL);
INSERT INTO client VALUES(6,'EA:E3:DD:09:39:17',1683521383,1683521395,'GameBoy');
CREATE TABLE client_by_group
(
    client_id INTEGER NOT NULL REFERENCES client (id),
    group_id INTEGER NOT NULL REFERENCES "group" (id),
    PRIMARY KEY (client_id, group_id)
);
INSERT INTO client_by_group(rowid,client_id,group_id) VALUES(1,1,1);
INSERT INTO client_by_group(rowid,client_id,group_id) VALUES(2,2,1);
INSERT INTO client_by_group(rowid,client_id,group_id) VALUES(3,3,0);
INSERT INTO client_by_group(rowid,client_id,group_id) VALUES(4,4,1);
INSERT INTO client_by_group(rowid,client_id,group_id) VALUES(5,5,1);
INSERT INTO client_by_group(rowid,client_id,group_id) VALUES(6,6,1);
COMMIT;
