CREATE TABLE IF NOT EXISTS `connections` (
  `id` INTEGER PRIMARY KEY,
  `timestamp` DATETIME DEFAULT NULL,
  `ip` VARCHAR(15) DEFAULT NULL,
  `remote_port` INT(11) DEFAULT NULL,
  `local_host` VARCHAR(15) DEFAULT NULL,
  `local_port` INT(11) DEFAULT NULL,
  `request` INTEGER DEFAULT NULL,
  `message` INTEGER DEFAULT NULL,
  `sensor` INT(4) DEFAULT NULL
);

CREATE INDEX IF NOT EXISTS `time_idx` ON `connections` (`timestamp`);
CREATE INDEX IF NOT EXISTS `ip_idx` ON `connections` (`ip`);
CREATE INDEX IF NOT EXISTS `ip2_idx` ON `connections` (`timestamp`, `ip`);

CREATE TABLE IF NOT EXISTS `messages` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `requests` (
  `id` INTEGER PRIMARY KEY,
  `accept` INTEGER DEFAULT NULL,
  `allow` INTEGER DEFAULT NULL,
  `callid` INTEGER DEFAULT NULL,
  `contact` INTEGER DEFAULT NULL,
  `con_len` INTEGER DEFAULT NULL,
  `con_type` INTEGER DEFAULT NULL,
  `cseq` INTEGER DEFAULT NULL,
  `expires` INTEGER DEFAULT NULL,
  `from` INTEGER DEFAULT NULL,
  `forwards` INTEGER DEFAULT NULL,
  `supported` INTEGER DEFAULT NULL,
  `to` INTEGER DEFAULT NULL,
  `agent` INTEGER DEFAULT NULL,
  `via` INTEGER DEFAULT NULL,
  `authorization` INTEGER DEFAULT NULL
);

CREATE TABLE IF NOT EXISTS `accepts` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `allows` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `callids` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `contacts` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `con_lens` (
  `id` INTEGER PRIMARY KEY,
  `value` INTEGER
);

CREATE TABLE IF NOT EXISTS `con_types` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `cseqs` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `expires` (
  `id` INTEGER PRIMARY KEY,
  `value` INTEGER
);

CREATE TABLE IF NOT EXISTS `froms` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `forwards` (
  `id` INTEGER PRIMARY KEY,
  `value` INTEGER
);

CREATE TABLE IF NOT EXISTS `supporteds` (
  `id` INTEGER PRIMARY KEY,
  `value` INTEGER
);

CREATE TABLE IF NOT EXISTS `tos` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `agents` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `vias` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `authorizations` (
  `id` INTEGER PRIMARY KEY,
  `value` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `unknown` (
  `id` INTEGER PRIMARY KEY,
  `header` VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS `sensors` (
  `id` INTEGER PRIMARY KEY,
  `name` VARCHAR(255) DEFAULT NULL UNIQUE
);

CREATE TABLE IF NOT EXISTS `geolocation` (
  `id` INTEGER PRIMARY KEY,
  `ip` VARCHAR(15) DEFAULT NULL UNIQUE,
  `country_name` VARCHAR(45) DEFAULT '',
  `country_iso_code` VARCHAR(2) DEFAULT '',
  `city_name` VARCHAR(128) DEFAULT '',
  `org` VARCHAR(128) DEFAULT '',
  `org_asn` INT(11) DEFAULT NULL
);
