CREATE TABLE `acc` (
	`id` int AUTO_INCREMENT NOT NULL,
	`method` varchar(16) NOT NULL,
	`from_tag` varchar(64) NOT NULL,
	`to_tag` varchar(64) NOT NULL,
	`callid` varchar(64) NOT NULL,
	`sip_code` varchar(3) NOT NULL,
	`sip_reason` varchar(32) NOT NULL,
	`time` timestamp NOT NULL,
	`duration` int NOT NULL DEFAULT 0,
	`ms_duration` int NOT NULL DEFAULT 0,
	`setuptime` int NOT NULL DEFAULT 0,
	`created` timestamp,
	`caller_ip` varchar(255),
	`caller_ua` varchar(255),
	`callee_ip` varchar(255),
	`callee_ua` varchar(255),
	`caller_id` varchar(255),
	`callee_id` varchar(255),
	`leg_status` varchar(255),
	CONSTRAINT `acc_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `active_watchers` (
	`id` int AUTO_INCREMENT NOT NULL,
	`presentity_uri` varchar(255) NOT NULL,
	`watcher_username` varchar(64) NOT NULL,
	`watcher_domain` varchar(64) NOT NULL,
	`to_user` varchar(64) NOT NULL,
	`to_domain` varchar(64) NOT NULL,
	`event` varchar(64) NOT NULL DEFAULT 'presence',
	`event_id` varchar(64),
	`to_tag` varchar(64) NOT NULL,
	`from_tag` varchar(64) NOT NULL,
	`callid` varchar(64) NOT NULL,
	`local_cseq` int NOT NULL,
	`remote_cseq` int NOT NULL,
	`contact` varchar(255) NOT NULL,
	`record_route` varchar(255),
	`expires` int NOT NULL,
	`status` int NOT NULL DEFAULT 2,
	`reason` varchar(64),
	`version` int NOT NULL DEFAULT 0,
	`socket_info` varchar(64) NOT NULL,
	`local_contact` varchar(255) NOT NULL,
	`sharing_tag` varchar(32),
	CONSTRAINT `active_watchers_id` PRIMARY KEY(`id`),
	CONSTRAINT `active_watchers_idx` UNIQUE(`presentity_uri`,`callid`,`to_tag`,`from_tag`)
);
--> statement-breakpoint
CREATE TABLE `config` (
	`id` int AUTO_INCREMENT NOT NULL,
	`name` varchar(255) NOT NULL,
	`value` varchar(255),
	`description` varchar(255) NOT NULL DEFAULT '',
	CONSTRAINT `config_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `dbaliases` (
	`id` int AUTO_INCREMENT NOT NULL,
	`alias_username` varchar(64) NOT NULL,
	`alias_domain` varchar(64) NOT NULL,
	`username` varchar(64) NOT NULL,
	`domain` varchar(64) NOT NULL,
	CONSTRAINT `dbaliases_id` PRIMARY KEY(`id`),
	CONSTRAINT `alias_idx` UNIQUE(`alias_username`,`alias_domain`)
);
--> statement-breakpoint
CREATE TABLE `dialog` (
	`dlg_id` bigint NOT NULL,
	`callid` varchar(255) NOT NULL,
	`from_uri` varchar(255) NOT NULL,
	`from_tag` varchar(64) NOT NULL,
	`to_uri` varchar(255) NOT NULL,
	`to_tag` varchar(64) NOT NULL,
	`mangled_from_uri` varchar(255),
	`mangled_to_uri` varchar(255),
	`caller_cseq` varchar(11) NOT NULL,
	`callee_cseq` varchar(11) NOT NULL,
	`caller_ping_cseq` int NOT NULL DEFAULT 0,
	`callee_ping_cseq` int NOT NULL DEFAULT 0,
	`caller_route_set` text,
	`callee_route_set` text,
	`caller_contact` varchar(255),
	`callee_contact` varchar(255),
	`caller_sock` varchar(64) NOT NULL,
	`callee_sock` varchar(64) NOT NULL,
	`state` int NOT NULL DEFAULT 0,
	`start_time` int NOT NULL DEFAULT 0,
	`timeout` int NOT NULL DEFAULT 0,
	`vars` binary,
	`profiles` text,
	`script_flags` varchar(255),
	`module_flags` int NOT NULL DEFAULT 0,
	`flags` int NOT NULL DEFAULT 0,
	`rt_on_answer` varchar(64),
	`rt_on_timeout` varchar(64),
	`rt_on_hangup` varchar(64),
	CONSTRAINT `dialog_dlg_id` PRIMARY KEY(`dlg_id`)
);
--> statement-breakpoint
CREATE TABLE `dialplan` (
	`id` int AUTO_INCREMENT NOT NULL,
	`dpid` int NOT NULL,
	`pr` int NOT NULL DEFAULT 0,
	`match_op` int NOT NULL,
	`match_exp` varchar(255) NOT NULL,
	`match_flags` int NOT NULL DEFAULT 0,
	`subst_exp` varchar(64),
	`repl_exp` varchar(32),
	`timerec` varchar(255),
	`disabled` int NOT NULL DEFAULT 0,
	`attrs` varchar(255),
	CONSTRAINT `dialplan_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `dids` (
	`id` int AUTO_INCREMENT NOT NULL,
	`alias_username` varchar(64) NOT NULL,
	`alias_domain` varchar(64) NOT NULL,
	`username` varchar(64) NOT NULL,
	`domain` varchar(64) NOT NULL,
	CONSTRAINT `dids_id` PRIMARY KEY(`id`),
	CONSTRAINT `alias_idx` UNIQUE(`alias_username`,`alias_domain`)
);
--> statement-breakpoint
CREATE TABLE `dispatcher` (
	`id` int AUTO_INCREMENT NOT NULL,
	`setid` int NOT NULL DEFAULT 0,
	`destination` varchar(192) NOT NULL,
	`socket` varchar(128),
	`state` int NOT NULL DEFAULT 0,
	`probe_mode` int NOT NULL DEFAULT 0,
	`weight` varchar(64) NOT NULL DEFAULT '1',
	`priority` int NOT NULL DEFAULT 0,
	`attrs` varchar(128),
	`description` varchar(64),
	CONSTRAINT `dispatcher_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `domain` (
	`id` int AUTO_INCREMENT NOT NULL,
	`domain` varchar(64) NOT NULL,
	`attrs` varchar(255),
	`last_modified` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `domain_id` PRIMARY KEY(`id`),
	CONSTRAINT `domain_idx` UNIQUE(`domain`)
);
--> statement-breakpoint
CREATE TABLE `dr_carriers` (
	`id` int AUTO_INCREMENT NOT NULL,
	`carrierid` varchar(64) NOT NULL,
	`gwlist` varchar(255) NOT NULL,
	`flags` int NOT NULL DEFAULT 0,
	`sort_alg` char(1) NOT NULL DEFAULT 'N',
	`state` int NOT NULL DEFAULT 0,
	`attrs` varchar(255),
	`description` varchar(128),
	CONSTRAINT `dr_carriers_id` PRIMARY KEY(`id`),
	CONSTRAINT `dr_carrier_idx` UNIQUE(`carrierid`)
);
--> statement-breakpoint
CREATE TABLE `dr_gateways` (
	`id` int AUTO_INCREMENT NOT NULL,
	`gwid` varchar(64) NOT NULL,
	`type` int NOT NULL DEFAULT 0,
	`address` varchar(128) NOT NULL,
	`strip` int NOT NULL DEFAULT 0,
	`pri_prefix` varchar(16),
	`attrs` varchar(255),
	`probe_mode` int NOT NULL DEFAULT 0,
	`state` int NOT NULL DEFAULT 0,
	`socket` varchar(128),
	`description` varchar(128),
	CONSTRAINT `dr_gateways_id` PRIMARY KEY(`id`),
	CONSTRAINT `dr_gw_idx` UNIQUE(`gwid`)
);
--> statement-breakpoint
CREATE TABLE `dr_groups` (
	`id` int AUTO_INCREMENT NOT NULL,
	`username` varchar(64) NOT NULL,
	`domain` varchar(128),
	`groupid` int NOT NULL DEFAULT 0,
	`description` varchar(128),
	CONSTRAINT `dr_groups_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `dr_partitions` (
	`id` int AUTO_INCREMENT NOT NULL,
	`partition_name` varchar(255) NOT NULL,
	`db_url` varchar(255) NOT NULL,
	`drd_table` varchar(255),
	`drr_table` varchar(255),
	`drg_table` varchar(255),
	`drc_table` varchar(255),
	`ruri_avp` varchar(255),
	`gw_id_avp` varchar(255),
	`gw_priprefix_avp` varchar(255),
	`gw_sock_avp` varchar(255),
	`rule_id_avp` varchar(255),
	`rule_prefix_avp` varchar(255),
	`carrier_id_avp` varchar(255),
	CONSTRAINT `dr_partitions_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `dr_rules` (
	`ruleid` int AUTO_INCREMENT NOT NULL,
	`groupid` varchar(255) NOT NULL,
	`prefix` varchar(64) NOT NULL,
	`timerec` varchar(255),
	`priority` int NOT NULL DEFAULT 0,
	`routeid` varchar(255),
	`gwlist` varchar(255),
	`sort_alg` char(1) NOT NULL DEFAULT 'N',
	`sort_profile` int,
	`attrs` varchar(255),
	`description` varchar(128),
	CONSTRAINT `dr_rules_ruleid` PRIMARY KEY(`ruleid`)
);
--> statement-breakpoint
CREATE TABLE `location` (
	`contact_id` bigint AUTO_INCREMENT NOT NULL,
	`username` varchar(64) NOT NULL,
	`domain` varchar(64),
	`contact` text NOT NULL,
	`received` varchar(255),
	`path` varchar(255),
	`expires` int NOT NULL DEFAULT 0,
	`q` float NOT NULL DEFAULT 1,
	`callid` varchar(255) NOT NULL DEFAULT 'Default-Call-ID',
	`cseq` int NOT NULL DEFAULT 13,
	`last_modified` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`flags` int NOT NULL DEFAULT 0,
	`cflags` varchar(255),
	`user_agent` varchar(255) NOT NULL DEFAULT '',
	`socket` varchar(64),
	`methods` int,
	`sip_instance` varchar(255),
	`kv_store` text,
	`attr` varchar(255),
	CONSTRAINT `location_contact_id` PRIMARY KEY(`contact_id`)
);
--> statement-breakpoint
CREATE TABLE `missed_calls` (
	`id` int AUTO_INCREMENT NOT NULL,
	`method` varchar(16) NOT NULL,
	`from_tag` varchar(64) NOT NULL,
	`to_tag` varchar(64) NOT NULL,
	`callid` varchar(64) NOT NULL,
	`sip_code` varchar(3) NOT NULL,
	`sip_reason` varchar(32) NOT NULL,
	`time` timestamp NOT NULL,
	`setuptime` int NOT NULL DEFAULT 0,
	`created` timestamp,
	CONSTRAINT `missed_calls_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `ocp_admin_privileges` (
	`id` int AUTO_INCREMENT NOT NULL,
	`first_name` varchar(64) NOT NULL,
	`last_name` varchar(64) NOT NULL,
	`username` varchar(64) NOT NULL,
	`password` varchar(64) NOT NULL,
	`ha1` varchar(256) DEFAULT '',
	`blocked` varchar(60),
	`failed_attempts` int NOT NULL DEFAULT 0,
	`available_tools` varchar(512) NOT NULL DEFAULT '',
	`permissions` varchar(512),
	`secret` varchar(20),
	CONSTRAINT `ocp_admin_privileges_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `ocp_boxes_config` (
	`id` bigint AUTO_INCREMENT NOT NULL,
	`name` varchar(64) NOT NULL,
	`mi_conn` varchar(64),
	`monit_conn` varchar(64),
	`monit_user` varchar(64),
	`monit_pass` varchar(64),
	`monit_ssl` int NOT NULL DEFAULT 0,
	`smonitcharts` int NOT NULL DEFAULT 1,
	`assoc_id` varchar(10) DEFAULT '-1',
	`desc` varchar(128) NOT NULL DEFAULT '',
	CONSTRAINT `ocp_boxes_config_id` PRIMARY KEY(`id`),
	CONSTRAINT `name_key` UNIQUE(`name`)
);
--> statement-breakpoint
CREATE TABLE `ocp_dashboard` (
	`id` bigint AUTO_INCREMENT NOT NULL,
	`name` varchar(64),
	`content` text,
	`order` int,
	`positions` text,
	CONSTRAINT `ocp_dashboard_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `ocp_db_config` (
	`id` int AUTO_INCREMENT NOT NULL,
	`config_name` varchar(64) NOT NULL,
	`db_host` varchar(64) NOT NULL,
	`db_port` varchar(64) NOT NULL,
	`db_user` varchar(64) NOT NULL,
	`db_pass` varchar(64),
	`db_name` varchar(64) NOT NULL,
	CONSTRAINT `ocp_db_config_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `ocp_extra_stats` (
	`id` int AUTO_INCREMENT NOT NULL,
	`name` varchar(255),
	`input` varchar(255),
	`box_id` int,
	`tool` varchar(60),
	`class` varchar(60),
	CONSTRAINT `ocp_extra_stats_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `ocp_monitored_stats` (
	`name` varchar(64) NOT NULL,
	`box_id` int NOT NULL DEFAULT 0,
	CONSTRAINT `ocp_monitored_stats_name_box_id_pk` PRIMARY KEY(`name`,`box_id`)
);
--> statement-breakpoint
CREATE TABLE `ocp_monitoring_stats` (
	`name` varchar(64) NOT NULL,
	`time` int NOT NULL,
	`value` varchar(64) NOT NULL DEFAULT '0',
	`box_id` int NOT NULL DEFAULT 0,
	CONSTRAINT `ocp_monitoring_stats_name_time_box_id_pk` PRIMARY KEY(`name`,`time`,`box_id`)
);
--> statement-breakpoint
CREATE TABLE `ocp_system_config` (
	`assoc_id` bigint AUTO_INCREMENT NOT NULL,
	`name` varchar(64),
	`desc` varchar(64) DEFAULT '',
	CONSTRAINT `ocp_system_config_assoc_id` PRIMARY KEY(`assoc_id`)
);
--> statement-breakpoint
CREATE TABLE `ocp_tools_config` (
	`id` bigint AUTO_INCREMENT NOT NULL,
	`module` varchar(64) NOT NULL,
	`param` varchar(64) NOT NULL,
	`value` binary,
	`box_id` varchar(15) NOT NULL DEFAULT '',
	CONSTRAINT `ocp_tools_config_id` PRIMARY KEY(`id`),
	CONSTRAINT `box_key` UNIQUE(`module`,`param`,`box_id`)
);
--> statement-breakpoint
CREATE TABLE `presentity` (
	`id` int AUTO_INCREMENT NOT NULL,
	`username` varchar(64) NOT NULL,
	`domain` varchar(64) NOT NULL,
	`event` varchar(64) NOT NULL,
	`etag` varchar(64) NOT NULL,
	`expires` int NOT NULL,
	`received_time` int NOT NULL,
	`body` binary,
	`extra_hdrs` binary,
	`sender` varchar(255),
	CONSTRAINT `presentity_id` PRIMARY KEY(`id`),
	CONSTRAINT `presentity_idx` UNIQUE(`username`,`domain`,`event`,`etag`)
);
--> statement-breakpoint
CREATE TABLE `pua` (
	`id` int AUTO_INCREMENT NOT NULL,
	`pres_uri` varchar(255) NOT NULL,
	`pres_id` varchar(255) NOT NULL,
	`event` int NOT NULL,
	`expires` int NOT NULL,
	`desired_expires` int NOT NULL,
	`flag` int NOT NULL,
	`etag` varchar(64),
	`tuple_id` varchar(64),
	`watcher_uri` varchar(255),
	`to_uri` varchar(255),
	`call_id` varchar(64),
	`to_tag` varchar(64),
	`from_tag` varchar(64),
	`cseq` int,
	`record_route` varchar(255),
	`contact` varchar(255),
	`remote_contact` varchar(255),
	`version` int,
	`extra_headers` varchar(255),
	`sharing_tag` varchar(32),
	CONSTRAINT `pua_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `rtpproxy_sockets` (
	`id` int AUTO_INCREMENT NOT NULL,
	`rtpproxy_sock` varchar(255) NOT NULL,
	`set_id` int NOT NULL,
	CONSTRAINT `rtpproxy_sockets_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `subscriber` (
	`id` int AUTO_INCREMENT NOT NULL,
	`username` varchar(64) NOT NULL,
	`domain` varchar(64) NOT NULL,
	`password` varchar(25) NOT NULL,
	`ha1` varchar(64) NOT NULL,
	`ha1_sha256` varchar(64) NOT NULL,
	`ha1_sha512t256` varchar(64) NOT NULL,
	`cli` varchar(255),
	`acls` varchar(32) NOT NULL DEFAULT '',
	`cfaw_uri` varchar(255),
	`cfbs_uri` varchar(255),
	`cfna_uri` varchar(255),
	`cfnf_uri` varchar(255),
	CONSTRAINT `subscriber_id` PRIMARY KEY(`id`),
	CONSTRAINT `account_idx` UNIQUE(`username`,`domain`)
);
--> statement-breakpoint
CREATE TABLE `uri` (
	`id` int AUTO_INCREMENT NOT NULL,
	`username` varchar(64) NOT NULL,
	`domain` varchar(64) NOT NULL,
	`uri_user` varchar(64) NOT NULL,
	`last_modified` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `uri_id` PRIMARY KEY(`id`),
	CONSTRAINT `account_idx` UNIQUE(`username`,`domain`,`uri_user`)
);
--> statement-breakpoint
CREATE TABLE `usr_preferences` (
	`id` int AUTO_INCREMENT NOT NULL,
	`uuid` varchar(64) NOT NULL,
	`username` varchar(64) NOT NULL DEFAULT '0',
	`domain` varchar(64) NOT NULL,
	`attribute` varchar(32) NOT NULL,
	`type` int NOT NULL DEFAULT 0,
	`value` varchar(128) NOT NULL,
	`last_modified` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `usr_preferences_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `version` (
	`table_name` varchar(32) NOT NULL,
	`table_version` int NOT NULL DEFAULT 0,
	CONSTRAINT `t_name_idx` UNIQUE(`table_name`)
);
--> statement-breakpoint
CREATE TABLE `watchers` (
	`id` int AUTO_INCREMENT NOT NULL,
	`presentity_uri` varchar(255) NOT NULL,
	`watcher_username` varchar(64) NOT NULL,
	`watcher_domain` varchar(64) NOT NULL,
	`event` varchar(64) NOT NULL DEFAULT 'presence',
	`status` int NOT NULL,
	`reason` varchar(64),
	`inserted_time` int NOT NULL,
	CONSTRAINT `watchers_id` PRIMARY KEY(`id`),
	CONSTRAINT `watcher_idx` UNIQUE(`presentity_uri`,`watcher_username`,`watcher_domain`,`event`)
);
--> statement-breakpoint
CREATE TABLE `xcap` (
	`id` int AUTO_INCREMENT NOT NULL,
	`username` varchar(64) NOT NULL,
	`domain` varchar(64) NOT NULL,
	`doc` binary NOT NULL,
	`doc_type` int NOT NULL,
	`etag` varchar(64) NOT NULL,
	`source` int NOT NULL,
	`doc_uri` varchar(255) NOT NULL,
	`port` int NOT NULL,
	CONSTRAINT `xcap_id` PRIMARY KEY(`id`),
	CONSTRAINT `account_doc_type_idx` UNIQUE(`username`,`domain`,`doc_type`,`doc_uri`)
);
--> statement-breakpoint
CREATE TABLE `address` (
	`id` int AUTO_INCREMENT NOT NULL,
	`grp` int NOT NULL DEFAULT 0,
	`ip` varchar(50) NOT NULL,
	`mask` tinyint NOT NULL,
	`port` int NOT NULL DEFAULT 0,
	`proto` varchar(4) NOT NULL DEFAULT 'any',
	`pattern` varchar(64),
	`context_info` varchar(32),
	CONSTRAINT `address_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE INDEX `callid_idx` ON `acc` (`callid`);--> statement-breakpoint
CREATE INDEX `target_idx` ON `dbaliases` (`username`,`domain`);--> statement-breakpoint
CREATE INDEX `target_idx` ON `dids` (`username`,`domain`);--> statement-breakpoint
CREATE INDEX `callid_idx` ON `missed_calls` (`callid`);--> statement-breakpoint
CREATE INDEX `del1_idx` ON `pua` (`pres_uri`,`event`);--> statement-breakpoint
CREATE INDEX `del2_idx` ON `pua` (`expires`);--> statement-breakpoint
CREATE INDEX `update_idx` ON `pua` (`pres_uri`,`pres_id`,`flag`,`event`);--> statement-breakpoint
CREATE INDEX `username_idx` ON `subscriber` (`username`);--> statement-breakpoint
CREATE INDEX `ua_idx` ON `usr_preferences` (`uuid`,`attribute`);--> statement-breakpoint
CREATE INDEX `uda_idx` ON `usr_preferences` (`username`,`domain`,`attribute`);--> statement-breakpoint
CREATE INDEX `value_idx` ON `usr_preferences` (`value`);--> statement-breakpoint
CREATE INDEX `source_idx` ON `xcap` (`source`);