VACUUM;

CREATE TABLE IF NOT EXISTS "ServerType" (
    "ServerId" INTEGER PRIMARY KEY AUTOINCREMENT,
    "Type" TEXT NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS "HttpVersion" (
    "HttpId" INTEGER PRIMARY KEY AUTOINCREMENT,
    "Version" TEXT NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS "CertificateIssuerCountry" (
	"CertificateIssuerId" INTEGER PRIMARY KEY AUTOINCREMENT,
	"Country" TEXT NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS "CertificateOrganizationName" (
	"CertificateOrganizationId" INTEGER PRIMARY KEY AUTOINCREMENT,
	"Name" TEXT NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS "TlsVersion" (
	"TlsId" INTEGER PRIMARY KEY AUTOINCREMENT,
	"Version" TEXT NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS "CipherSuite" (
	"CipherId" INTEGER PRIMARY KEY AUTOINCREMENT,
	"Suite" TEXT NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS "KeyExchangeAlgorithm" (
	"KeyExchangeId" INTEGER PRIMARY KEY AUTOINCREMENT,
	"Algorithm" TEXT NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS "PublicKeyType" (
	"PublicKeyId" INTEGER PRIMARY KEY AUTOINCREMENT,
	"Type" TEXT NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS "AcceptEncoding" (
	"AcceptId" INTEGER PRIMARY KEY AUTOINCREMENT,
	"Encoding" TEXT NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS "ALPN" (
	"ALPNId" INTEGER PRIMARY KEY AUTOINCREMENT,
	"ALPNValue" TEXT NOT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS "Connection" (
	"ConnectionId" INTEGER PRIMARY KEY AUTOINCREMENT,
	"ConnectionValue" TEXT NOT NULL UNIQUE
);

DROP TABLE Filtered;

CREATE TABLE "Filtered" (
	"Id"	INTEGER NOT NULL,
	"Ip1"	INTEGER NOT NULL,
	"Ip2"	INTEGER NOT NULL,
	"Ip3"	INTEGER NOT NULL,
	"Ip4"	INTEGER NOT NULL,
	"Port1"	INTEGER NOT NULL,
	"Port2"	INTEGER NOT NULL,
	"Title1"	TEXT NOT NULL,
	"Title2"	TEXT NOT NULL,
	"Description1"	TEXT NOT NULL,
	"Description2"	TEXT NOT NULL,
	"Url1"	TEXT NOT NULL,
	"Url2"	TEXT NOT NULL,
	"ServerType1"	INTEGER NOT NULL,
	"ServerType2"	INTEGER NOT NULL,
	"RobotsTXT1"	TEXT NOT NULL,
	"RobotsTXT2"	TEXT NOT NULL,
	"HttpVersion1"	INTEGER NOT NULL,
	"HttpVersion2"	INTEGER NOT NULL,
	"CertificateIssuerCountry"	INTEGER NOT NULL,
	"CertificateOrganizationName"	INTEGER NOT NULL,
	"IpV6"	TEXT NOT NULL,
	"TlsVersion"	INTEGER NOT NULL,
	"CipherSuite"	INTEGER NOT NULL,
	"KeyExchangeAlgorithm"	INTEGER NOT NULL,
	"PublicKeyType1"	INTEGER NOT NULL,
	"PublicKeyType2"	INTEGER NOT NULL,
	"PublicKeyType3"	INTEGER NOT NULL,
	"AcceptEncoding1"	INTEGER NOT NULL,
	"AcceptEncoding2"	INTEGER NOT NULL,
	"ALPN"	INTEGER NOT NULL,
	"Connection1"	INTEGER NOT NULL,
	"Connection2"	INTEGER NOT NULL,
	PRIMARY KEY("Id" AUTOINCREMENT),
	FOREIGN KEY("ALPN") REFERENCES "ALPN"("ALPNId"),
	FOREIGN KEY("AcceptEncoding1") REFERENCES "AcceptEncoding"("AcceptId"),
	FOREIGN KEY("AcceptEncoding2") REFERENCES "AcceptEncoding"("AcceptId"),
	FOREIGN KEY("CertificateIssuerCountry") REFERENCES "CertificateIssuerCountry"("CertificateIssuerId"),
	FOREIGN KEY("CertificateOrganizationName") REFERENCES "CertificateOrganizationName"("CertificateOrganizationId"),
	FOREIGN KEY("CipherSuite") REFERENCES "CipherSuite"("CipherId"),
	FOREIGN KEY("Connection1") REFERENCES "Connection"("ConnectionId"),
	FOREIGN KEY("Connection2") REFERENCES "Connection"("ConnectionId"),
	FOREIGN KEY("HttpVersion1") REFERENCES "HttpVersion"("HttpId"),
	FOREIGN KEY("HttpVersion2") REFERENCES "HttpVersion"("HttpId"),
	FOREIGN KEY("KeyExchangeAlgorithm") REFERENCES "KeyExchangeAlgorithm"("KeyExchangeId"),
	FOREIGN KEY("PublicKeyType1") REFERENCES "PublicKeyType"("PublicKeyId"),
	FOREIGN KEY("PublicKeyType2") REFERENCES "PublicKeyType"("PublicKeyId"),
	FOREIGN KEY("PublicKeyType3") REFERENCES "PublicKeyType"("PublicKeyId"),
	FOREIGN KEY("ServerType1") REFERENCES "ServerType"("ServerId"),
	FOREIGN KEY("ServerType2") REFERENCES "ServerType"("ServerId"),
	FOREIGN KEY("TlsVersion") REFERENCES "TlsVersion"("TlsId")
)