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

CREATE TABLE IF NOT EXISTS `messages` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

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

CREATE TABLE IF NOT EXISTS `accepts` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `allows` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `callids` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `contacts` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `con_lens` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` INT DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `con_types` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `cseqs` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `expires` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` INT DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `froms` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `forwards` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` INT DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `supporteds` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` INT DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `tos` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `agents` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `vias` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `authorizations` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `value` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`value`)
);

CREATE TABLE IF NOT EXISTS `unknown` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `header` VARCHAR(255),
  PRIMARY KEY (`id`),
  UNIQUE (`header`)
);

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

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