-- teamspeak.api_keys definition

CREATE TABLE `api_keys` (
  `api_key_id` int(11) NOT NULL AUTO_INCREMENT,
  `server_id` int(10) unsigned NOT NULL,
  `api_key_hash` varchar(44) NOT NULL,
  `api_key_owner_dbid` int(10) unsigned NOT NULL,
  `api_key_scope` int(10) unsigned NOT NULL,
  `api_key_created_at` int(10) unsigned NOT NULL,
  `api_key_expires_at` int(10) unsigned NOT NULL,
  `api_key_custom_id` varchar(255) NOT NULL,
  PRIMARY KEY (`api_key_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.bans definition

CREATE TABLE `bans` (
  `ban_id` int(11) NOT NULL AUTO_INCREMENT,
  `server_id` int(10) unsigned DEFAULT NULL,
  `ban_ip` varchar(255) DEFAULT NULL,
  `ban_name` varchar(2048) DEFAULT NULL,
  `ban_uid` varchar(255) DEFAULT NULL,
  `ban_timestamp` int(10) unsigned DEFAULT NULL,
  `ban_length` int(10) unsigned DEFAULT NULL,
  `ban_invoker_client_id` int(10) unsigned DEFAULT NULL,
  `ban_invoker_uid` varchar(64) DEFAULT NULL,
  `ban_invoker_name` varchar(255) DEFAULT NULL,
  `ban_reason` varchar(255) DEFAULT NULL,
  `ban_enforcements` int(10) unsigned DEFAULT 0,
  `ban_hash` varchar(255) DEFAULT NULL,
  `ban_mytsid` varchar(44) DEFAULT NULL,
  `ban_lastnickname` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`ban_id`),
  KEY `index_bans_serverid` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.bindings definition

CREATE TABLE `bindings` (
  `binding_id` int(11) NOT NULL AUTO_INCREMENT,
  `ip` varchar(45) NOT NULL,
  `type` int(11) DEFAULT NULL,
  PRIMARY KEY (`binding_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.channel_properties definition

CREATE TABLE `channel_properties` (
  `server_id` int(10) unsigned DEFAULT NULL,
  `id` int(10) unsigned DEFAULT NULL,
  `ident` varchar(255) NOT NULL,
  `value` varchar(8192) DEFAULT NULL,
  KEY `index_channel_properties_id` (`id`),
  KEY `index_channel_properties_serverid` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.channels definition

CREATE TABLE `channels` (
  `channel_id` int(11) NOT NULL AUTO_INCREMENT,
  `channel_parent_id` int(10) unsigned DEFAULT NULL,
  `server_id` int(10) unsigned NOT NULL,
  `org_channel_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`channel_id`),
  KEY `index_channels_id` (`channel_id`),
  KEY `index_channels_serverid` (`server_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.client_properties definition

CREATE TABLE `client_properties` (
  `server_id` int(10) unsigned DEFAULT NULL,
  `id` int(10) unsigned DEFAULT NULL,
  `ident` varchar(100) NOT NULL,
  `value` varchar(255) DEFAULT NULL,
  KEY `index_client_properties_id` (`id`),
  KEY `index_client_properties_serverid` (`server_id`),
  KEY `index_client_properties_serverid_id_ident` (`server_id`,`id`,`ident`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.clients definition

CREATE TABLE `clients` (
  `client_id` int(11) NOT NULL AUTO_INCREMENT,
  `server_id` int(10) unsigned DEFAULT NULL,
  `client_unique_id` varchar(100) DEFAULT NULL,
  `client_nickname` varchar(100) DEFAULT NULL,
  `client_login_name` varchar(20) DEFAULT NULL,
  `client_login_password` varchar(100) DEFAULT NULL,
  `client_lastconnected` int(10) unsigned DEFAULT NULL,
  `client_totalconnections` int(10) unsigned DEFAULT 0,
  `client_month_upload` bigint(20) unsigned DEFAULT 0,
  `client_month_download` bigint(20) unsigned DEFAULT 0,
  `client_total_upload` bigint(20) unsigned DEFAULT 0,
  `client_total_download` bigint(20) unsigned DEFAULT 0,
  `client_lastip` varchar(45) DEFAULT NULL,
  `org_client_id` int(11) DEFAULT NULL,
  `homebase_since` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`client_id`),
  UNIQUE KEY `client_login_name` (`client_login_name`),
  KEY `index_clients_id` (`client_id`),
  KEY `index_clients_serverid` (`server_id`),
  KEY `index_clients_lastconnectedserverid` (`client_lastconnected`,`server_id`),
  KEY `index_clients_uid` (`client_unique_id`,`server_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.complains definition

CREATE TABLE `complains` (
  `server_id` int(10) unsigned DEFAULT NULL,
  `complain_from_client_id` int(10) unsigned DEFAULT NULL,
  `complain_to_client_id` int(10) unsigned DEFAULT NULL,
  `complain_message` varchar(255) DEFAULT NULL,
  `complain_timestamp` int(10) unsigned DEFAULT NULL,
  `complain_hash` varchar(255) DEFAULT NULL,
  KEY `index_complains_serverid` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.custom_fields definition

CREATE TABLE `custom_fields` (
  `server_id` int(10) unsigned NOT NULL,
  `client_id` int(10) unsigned NOT NULL,
  `ident` varchar(100) NOT NULL,
  `value` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`server_id`,`client_id`,`ident`),
  KEY `index_custom_fields_by_client` (`server_id`,`client_id`),
  KEY `index_custom_fields_by_ident` (`server_id`,`ident`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.events definition

CREATE TABLE `events` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `data` mediumtext NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.group_channel_to_client definition

CREATE TABLE `group_channel_to_client` (
  `group_id` int(10) unsigned NOT NULL,
  `server_id` int(10) unsigned NOT NULL,
  `id1` int(10) unsigned NOT NULL,
  `id2` int(10) unsigned NOT NULL,
  KEY `index_group_channel_to_client_id` (`group_id`),
  KEY `index_group_channel_to_client_serverid` (`server_id`),
  KEY `index_group_channel_to_client_id1` (`id1`),
  KEY `index_group_channel_to_client_id2` (`id2`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.group_server_to_client definition

CREATE TABLE `group_server_to_client` (
  `group_id` int(10) unsigned NOT NULL,
  `server_id` int(10) unsigned NOT NULL,
  `id1` int(10) unsigned NOT NULL,
  `id2` int(10) unsigned NOT NULL,
  KEY `index_group_server_to_client_id` (`group_id`),
  KEY `index_group_server_to_client_serverid` (`server_id`),
  KEY `index_group_server_to_client_id1` (`id1`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.groups_channel definition

CREATE TABLE `groups_channel` (
  `group_id` int(11) NOT NULL AUTO_INCREMENT,
  `server_id` int(10) unsigned NOT NULL,
  `name` varchar(50) NOT NULL,
  `type` int(11) NOT NULL,
  `org_group_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`group_id`),
  KEY `index_groups_channel_id` (`group_id`),
  KEY `index_groups_channel_serverid` (`server_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.groups_server definition

CREATE TABLE `groups_server` (
  `group_id` int(11) NOT NULL AUTO_INCREMENT,
  `server_id` int(10) unsigned NOT NULL,
  `name` varchar(50) NOT NULL,
  `type` int(11) NOT NULL,
  `org_group_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`group_id`),
  KEY `index_groups_server_id` (`group_id`),
  KEY `index_groups_server_serverid` (`server_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.instance_properties definition

CREATE TABLE `instance_properties` (
  `server_id` int(10) unsigned DEFAULT NULL,
  `string_id` varchar(255) DEFAULT NULL,
  `id` int(10) unsigned DEFAULT NULL,
  `ident` varchar(100) NOT NULL,
  `value` varchar(255) DEFAULT NULL,
  KEY `index_instance_properties_id` (`id`),
  KEY `index_instance_properties_string_id` (`string_id`(191)),
  KEY `index_instance_properties_serverid` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.integration_actions definition

CREATE TABLE `integration_actions` (
  `integration_action_id` int(11) NOT NULL AUTO_INCREMENT,
  `server_id` int(10) unsigned NOT NULL,
  `integration_id` varchar(36) NOT NULL,
  `integration_response_type` int(10) unsigned NOT NULL,
  `integration_response_value` varchar(255) NOT NULL,
  `integration_action_type` int(10) unsigned NOT NULL,
  `integration_action_value` varchar(255) NOT NULL,
  PRIMARY KEY (`integration_action_id`),
  KEY `index_integration_actions_server_id` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.integrations definition

CREATE TABLE `integrations` (
  `server_id` int(10) unsigned NOT NULL,
  `integration_id` varchar(36) NOT NULL,
  `integration_type` int(10) unsigned NOT NULL,
  `integration_user_info` varchar(4096) DEFAULT NULL,
  PRIMARY KEY (`server_id`,`integration_id`),
  KEY `index_integrations_server_id` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.messages definition

CREATE TABLE `messages` (
  `message_id` int(11) NOT NULL AUTO_INCREMENT,
  `server_id` int(10) unsigned DEFAULT NULL,
  `message_from_client_id` int(10) unsigned DEFAULT NULL,
  `message_from_client_uid` varchar(64) DEFAULT NULL,
  `message_to_client_id` int(10) unsigned DEFAULT NULL,
  `message_subject` varchar(255) DEFAULT NULL,
  `message_msg` text DEFAULT NULL,
  `message_timestamp` int(10) unsigned DEFAULT NULL,
  `message_flag_read` int(11) DEFAULT 0,
  PRIMARY KEY (`message_id`),
  KEY `index_messages_serverid` (`server_id`),
  KEY `index_messages_msgidtoclid_read` (`message_to_client_id`,`message_flag_read`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.perm_channel definition

CREATE TABLE `perm_channel` (
  `server_id` int(10) unsigned NOT NULL,
  `id1` int(10) unsigned NOT NULL,
  `id2` int(10) unsigned NOT NULL,
  `perm_id` varchar(100) NOT NULL,
  `perm_value` int(11) DEFAULT NULL,
  `perm_negated` int(11) DEFAULT NULL,
  `perm_skip` int(11) DEFAULT NULL,
  KEY `index_perm_channel_serverid` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.perm_channel_clients definition

CREATE TABLE `perm_channel_clients` (
  `server_id` int(10) unsigned NOT NULL,
  `id1` int(10) unsigned NOT NULL,
  `id2` int(10) unsigned NOT NULL,
  `perm_id` varchar(100) NOT NULL,
  `perm_value` int(11) DEFAULT NULL,
  `perm_negated` int(11) DEFAULT NULL,
  `perm_skip` int(11) DEFAULT NULL,
  KEY `index_perm_channel_clients_serverid` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.perm_channel_groups definition

CREATE TABLE `perm_channel_groups` (
  `server_id` int(10) unsigned NOT NULL,
  `id1` int(10) unsigned NOT NULL,
  `id2` int(10) unsigned NOT NULL,
  `perm_id` varchar(100) NOT NULL,
  `perm_value` int(11) DEFAULT NULL,
  `perm_negated` int(11) DEFAULT NULL,
  `perm_skip` int(11) DEFAULT NULL,
  KEY `index_perm_channel_groups_serverid` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.perm_client definition

CREATE TABLE `perm_client` (
  `server_id` int(10) unsigned NOT NULL,
  `id1` int(10) unsigned NOT NULL,
  `id2` int(10) unsigned NOT NULL,
  `perm_id` varchar(100) NOT NULL,
  `perm_value` int(11) DEFAULT NULL,
  `perm_negated` int(11) DEFAULT NULL,
  `perm_skip` int(11) DEFAULT NULL,
  KEY `index_perm_client_serverid` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.perm_server_group definition

CREATE TABLE `perm_server_group` (
  `server_id` int(10) unsigned NOT NULL,
  `id1` int(10) unsigned NOT NULL,
  `id2` int(10) unsigned NOT NULL,
  `perm_id` varchar(100) NOT NULL,
  `perm_value` int(11) DEFAULT NULL,
  `perm_negated` int(11) DEFAULT NULL,
  `perm_skip` int(11) DEFAULT NULL,
  KEY `index_perm_server_group_serverid` (`server_id`),
  KEY `index_perm_server_group_serverid_negated` (`server_id`,`id1`,`perm_id`,`perm_value`,`perm_negated`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.revocations definition

CREATE TABLE `revocations` (
  `revocation_key` varchar(44) NOT NULL,
  `revocation_type` int(10) unsigned NOT NULL,
  `revocation_expiration` int(10) unsigned NOT NULL,
  PRIMARY KEY (`revocation_type`,`revocation_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.server_properties definition

CREATE TABLE `server_properties` (
  `server_id` int(10) unsigned DEFAULT NULL,
  `id` int(10) unsigned DEFAULT NULL,
  `ident` varchar(100) NOT NULL,
  `value` varchar(2048) DEFAULT NULL,
  KEY `index_server_properties_id` (`id`),
  KEY `index_server_prop_sid` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.servers definition

CREATE TABLE `servers` (
  `server_id` int(11) AUTO_INCREMENT,
  `server_port` int(10) unsigned DEFAULT NULL,
  `server_autostart` int(10) unsigned DEFAULT NULL,
  `server_machine_id` varchar(50) DEFAULT NULL,
  `server_month_upload` bigint(20) unsigned DEFAULT 0,
  `server_month_download` bigint(20) unsigned DEFAULT 0,
  `server_total_upload` bigint(20) unsigned DEFAULT 0,
  `server_total_download` bigint(20) unsigned DEFAULT 0,
  PRIMARY KEY (`server_id`),
  KEY `index_servers_serverid` (`server_id`),
  KEY `index_servers_port` (`server_port`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.teamspeak3_metadata definition

CREATE TABLE `teamspeak3_metadata` (
  `ident` varchar(100) NOT NULL,
  `value` varchar(255) DEFAULT NULL,
  UNIQUE KEY `ident` (`ident`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.temporary_passwords definition

CREATE TABLE `temporary_passwords` (
  `server_id` int(10) unsigned NOT NULL,
  `temporary_password_hash` varchar(100) NOT NULL,
  `temporary_password_plaintext` varchar(255) NOT NULL,
  `temporary_password_creator_id` int(11) NOT NULL,
  `temporary_password_start_timestamp` int(10) unsigned NOT NULL,
  `temporary_password_end_timestamp` int(10) unsigned NOT NULL,
  `temporary_password_channel_id` int(11) NOT NULL,
  `temporary_password_channel_password` varchar(255) DEFAULT NULL,
  `temporary_password_description` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`server_id`,`temporary_password_hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;


-- teamspeak.tokens definition

CREATE TABLE `tokens` (
  `server_id` int(10) unsigned DEFAULT NULL,
  `token_key` varchar(50) NOT NULL,
  `token_type` int(11) DEFAULT NULL,
  `token_id1` int(10) unsigned DEFAULT NULL,
  `token_id2` int(10) unsigned DEFAULT NULL,
  `token_created` int(10) unsigned DEFAULT NULL,
  `token_description` varchar(255) DEFAULT NULL,
  `token_customset` varchar(255) DEFAULT NULL,
  `token_from_client_id` int(10) unsigned DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;