-- CreateTable
CREATE TABLE `acc` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `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` DATETIME(3) NOT NULL,
    `duration` INTEGER NOT NULL DEFAULT 0,
    `ms_duration` INTEGER NOT NULL DEFAULT 0,
    `setuptime` INTEGER NOT NULL DEFAULT 0,
    `created` DATETIME(3) NULL,
    `caller_ip` VARCHAR(255) NULL,
    `caller_ua` VARCHAR(255) NULL,
    `callee_ip` VARCHAR(255) NULL,
    `callee_ua` VARCHAR(255) NULL,
    `caller_id` VARCHAR(255) NULL,
    `callee_id` VARCHAR(255) NULL,
    `leg_status` VARCHAR(255) NULL,

    INDEX `callid_idx`(`callid`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `active_watchers` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `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) NULL,
    `to_tag` VARCHAR(64) NOT NULL,
    `from_tag` VARCHAR(64) NOT NULL,
    `callid` VARCHAR(64) NOT NULL,
    `local_cseq` INTEGER NOT NULL,
    `remote_cseq` INTEGER NOT NULL,
    `contact` VARCHAR(255) NOT NULL,
    `record_route` VARCHAR(191) NULL,
    `expires` INTEGER NOT NULL,
    `status` INTEGER NOT NULL DEFAULT 2,
    `reason` VARCHAR(64) NULL,
    `version` INTEGER NOT NULL DEFAULT 0,
    `socket_info` VARCHAR(64) NOT NULL,
    `local_contact` VARCHAR(255) NOT NULL,
    `sharing_tag` VARCHAR(32) NULL,

    UNIQUE INDEX `active_watchers_presentity_uri_callid_to_tag_from_tag_key`(`presentity_uri`, `callid`, `to_tag`, `from_tag`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `config` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(255) NOT NULL,
    `value` VARCHAR(255) NULL,
    `description` VARCHAR(255) NOT NULL DEFAULT '',

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `dbaliases` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `alias_username` VARCHAR(64) NOT NULL,
    `alias_domain` VARCHAR(64) NOT NULL,
    `username` VARCHAR(64) NOT NULL,
    `domain` VARCHAR(64) NOT NULL,

    INDEX `target_idx`(`username`, `domain`),
    UNIQUE INDEX `dbaliases_alias_username_alias_domain_key`(`alias_username`, `alias_domain`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
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) NULL,
    `mangled_to_uri` VARCHAR(255) NULL,
    `caller_cseq` VARCHAR(11) NOT NULL,
    `callee_cseq` VARCHAR(11) NOT NULL,
    `caller_ping_cseq` INTEGER NOT NULL DEFAULT 0,
    `callee_ping_cseq` INTEGER NOT NULL DEFAULT 0,
    `caller_route_set` VARCHAR(191) NULL,
    `callee_route_set` VARCHAR(191) NULL,
    `caller_contact` VARCHAR(255) NULL,
    `callee_contact` VARCHAR(255) NULL,
    `caller_sock` VARCHAR(64) NOT NULL,
    `callee_sock` VARCHAR(64) NOT NULL,
    `state` INTEGER NOT NULL DEFAULT 0,
    `start_time` INTEGER NOT NULL DEFAULT 0,
    `timeout` INTEGER NOT NULL DEFAULT 0,
    `vars` LONGBLOB NULL,
    `profiles` VARCHAR(191) NULL,
    `script_flags` VARCHAR(255) NULL,
    `module_flags` INTEGER NOT NULL DEFAULT 0,
    `flags` INTEGER NOT NULL DEFAULT 0,
    `rt_on_answer` VARCHAR(64) NULL,
    `rt_on_timeout` VARCHAR(64) NULL,
    `rt_on_hangup` VARCHAR(64) NULL,

    PRIMARY KEY (`dlg_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `dialplan` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `dpid` INTEGER NOT NULL,
    `pr` INTEGER NOT NULL DEFAULT 0,
    `match_op` INTEGER NOT NULL,
    `match_exp` VARCHAR(255) NOT NULL,
    `match_flags` INTEGER NOT NULL DEFAULT 0,
    `subst_exp` VARCHAR(64) NULL,
    `repl_exp` VARCHAR(32) NULL,
    `timerec` VARCHAR(255) NULL,
    `disabled` INTEGER NOT NULL DEFAULT 0,
    `attrs` VARCHAR(255) NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `dids` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `alias_username` VARCHAR(64) NOT NULL,
    `alias_domain` VARCHAR(64) NOT NULL,
    `username` VARCHAR(64) NOT NULL,
    `domain` VARCHAR(64) NOT NULL,

    INDEX `target_idx`(`username`, `domain`),
    UNIQUE INDEX `dids_alias_username_alias_domain_key`(`alias_username`, `alias_domain`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `dispatcher` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `setid` INTEGER NOT NULL DEFAULT 0,
    `destination` VARCHAR(192) NOT NULL,
    `socket` VARCHAR(128) NULL,
    `state` INTEGER NOT NULL DEFAULT 0,
    `probe_mode` INTEGER NOT NULL DEFAULT 0,
    `weight` VARCHAR(64) NOT NULL DEFAULT '1',
    `priority` INTEGER NOT NULL DEFAULT 0,
    `attrs` VARCHAR(128) NULL,
    `description` VARCHAR(64) NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `domain` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `domain` VARCHAR(64) NOT NULL,
    `attrs` VARCHAR(255) NULL,
    `last_modified` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    UNIQUE INDEX `domain_domain_key`(`domain`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `dr_carriers` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `carrierid` VARCHAR(64) NOT NULL,
    `gwlist` VARCHAR(255) NOT NULL,
    `flags` INTEGER NOT NULL DEFAULT 0,
    `sort_alg` CHAR(1) NOT NULL DEFAULT 'N',
    `state` INTEGER NOT NULL DEFAULT 0,
    `attrs` VARCHAR(255) NULL,
    `description` VARCHAR(128) NULL,

    UNIQUE INDEX `dr_carriers_carrierid_key`(`carrierid`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `dr_gateways` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `gwid` VARCHAR(64) NOT NULL,
    `type` INTEGER NOT NULL DEFAULT 0,
    `address` VARCHAR(128) NOT NULL,
    `strip` INTEGER NOT NULL DEFAULT 0,
    `pri_prefix` VARCHAR(16) NULL,
    `attrs` VARCHAR(255) NULL,
    `probe_mode` INTEGER NOT NULL DEFAULT 0,
    `state` INTEGER NOT NULL DEFAULT 0,
    `socket` VARCHAR(128) NULL,
    `description` VARCHAR(128) NULL,

    UNIQUE INDEX `dr_gateways_gwid_key`(`gwid`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `dr_groups` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(64) NOT NULL,
    `domain` VARCHAR(128) NULL,
    `groupid` INTEGER NOT NULL DEFAULT 0,
    `description` VARCHAR(128) NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `dr_partitions` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `partition_name` VARCHAR(255) NOT NULL,
    `db_url` VARCHAR(255) NOT NULL,
    `drd_table` VARCHAR(255) NULL,
    `drr_table` VARCHAR(255) NULL,
    `drg_table` VARCHAR(255) NULL,
    `drc_table` VARCHAR(255) NULL,
    `ruri_avp` VARCHAR(255) NULL,
    `gw_id_avp` VARCHAR(255) NULL,
    `gw_priprefix_avp` VARCHAR(255) NULL,
    `gw_sock_avp` VARCHAR(255) NULL,
    `rule_id_avp` VARCHAR(255) NULL,
    `rule_prefix_avp` VARCHAR(255) NULL,
    `carrier_id_avp` VARCHAR(255) NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `dr_rules` (
    `ruleid` INTEGER NOT NULL AUTO_INCREMENT,
    `groupid` VARCHAR(255) NOT NULL,
    `prefix` VARCHAR(64) NOT NULL,
    `timerec` VARCHAR(255) NULL,
    `priority` INTEGER NOT NULL DEFAULT 0,
    `routeid` VARCHAR(255) NULL,
    `gwlist` VARCHAR(255) NULL,
    `sort_alg` CHAR(1) NOT NULL DEFAULT 'N',
    `sort_profile` INTEGER NULL,
    `attrs` VARCHAR(255) NULL,
    `description` VARCHAR(128) NULL,

    PRIMARY KEY (`ruleid`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `location` (
    `contact_id` BIGINT NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(64) NOT NULL,
    `domain` VARCHAR(64) NULL,
    `contact` VARCHAR(191) NOT NULL,
    `received` VARCHAR(255) NULL,
    `path` VARCHAR(255) NULL,
    `expires` INTEGER NOT NULL DEFAULT 0,
    `q` DOUBLE NOT NULL DEFAULT 1.00,
    `callid` VARCHAR(255) NOT NULL DEFAULT 'Default-Call-ID',
    `cseq` INTEGER NOT NULL DEFAULT 13,
    `last_modified` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `flags` INTEGER NOT NULL DEFAULT 0,
    `cflags` VARCHAR(255) NULL,
    `user_agent` VARCHAR(255) NOT NULL DEFAULT '',
    `socket` VARCHAR(64) NULL,
    `methods` INTEGER NULL,
    `sip_instance` VARCHAR(255) NULL,
    `kv_store` VARCHAR(191) NULL,
    `attr` VARCHAR(255) NULL,

    PRIMARY KEY (`contact_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `missed_calls` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `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` DATETIME(3) NOT NULL,
    `setuptime` INTEGER NOT NULL DEFAULT 0,
    `created` DATETIME(3) NULL,

    INDEX `callid_idx`(`callid`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ocp_admin_privileges` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `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) NULL DEFAULT '',
    `blocked` VARCHAR(60) NULL,
    `failed_attempts` INTEGER NOT NULL DEFAULT 0,
    `available_tools` VARCHAR(512) NOT NULL DEFAULT '',
    `permissions` VARCHAR(512) NULL,
    `secret` VARCHAR(20) NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ocp_boxes_config` (
    `id` BIGINT NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(64) NOT NULL,
    `mi_conn` VARCHAR(64) NULL,
    `monit_conn` VARCHAR(64) NULL,
    `monit_user` VARCHAR(64) NULL,
    `monit_pass` VARCHAR(64) NULL,
    `monit_ssl` INTEGER NOT NULL DEFAULT 0,
    `smonitcharts` INTEGER NOT NULL DEFAULT 1,
    `assoc_id` VARCHAR(10) NULL DEFAULT '-1',
    `desc` VARCHAR(128) NOT NULL DEFAULT '',

    UNIQUE INDEX `ocp_boxes_config_name_key`(`name`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ocp_dashboard` (
    `id` BIGINT NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(64) NULL,
    `content` VARCHAR(191) NULL,
    `order` INTEGER NULL,
    `positions` VARCHAR(191) NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ocp_db_config` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `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) NULL,
    `db_name` VARCHAR(64) NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ocp_extra_stats` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(191) NULL,
    `input` VARCHAR(191) NULL,
    `box_id` INTEGER NULL,
    `tool` VARCHAR(60) NULL,
    `class` VARCHAR(60) NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ocp_monitored_stats` (
    `name` VARCHAR(64) NOT NULL,
    `box_id` INTEGER NOT NULL DEFAULT 0,

    PRIMARY KEY (`name`, `box_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ocp_monitoring_stats` (
    `name` VARCHAR(64) NOT NULL,
    `time` INTEGER NOT NULL,
    `value` VARCHAR(64) NOT NULL DEFAULT '0',
    `box_id` INTEGER NOT NULL DEFAULT 0,

    PRIMARY KEY (`name`, `time`, `box_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ocp_system_config` (
    `assoc_id` BIGINT NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(64) NULL,
    `desc` VARCHAR(64) NULL DEFAULT '',

    PRIMARY KEY (`assoc_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ocp_tools_config` (
    `id` BIGINT NOT NULL AUTO_INCREMENT,
    `module` VARCHAR(64) NOT NULL,
    `param` VARCHAR(64) NOT NULL,
    `value` LONGBLOB NULL,
    `box_id` VARCHAR(15) NOT NULL DEFAULT '',

    UNIQUE INDEX `ocp_tools_config_module_param_box_id_key`(`module`, `param`, `box_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `presentity` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(64) NOT NULL,
    `domain` VARCHAR(64) NOT NULL,
    `event` VARCHAR(64) NOT NULL,
    `etag` VARCHAR(64) NOT NULL,
    `expires` INTEGER NOT NULL,
    `received_time` INTEGER NOT NULL,
    `body` LONGBLOB NULL,
    `extra_hdrs` LONGBLOB NULL,
    `sender` VARCHAR(255) NULL,

    UNIQUE INDEX `presentity_username_domain_event_etag_key`(`username`, `domain`, `event`, `etag`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `pua` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `pres_uri` VARCHAR(255) NOT NULL,
    `pres_id` VARCHAR(255) NOT NULL,
    `event` INTEGER NOT NULL,
    `expires` INTEGER NOT NULL,
    `desired_expires` INTEGER NOT NULL,
    `flag` INTEGER NOT NULL,
    `etag` VARCHAR(64) NULL,
    `tuple_id` VARCHAR(64) NULL,
    `watcher_uri` VARCHAR(255) NULL,
    `to_uri` VARCHAR(255) NULL,
    `call_id` VARCHAR(64) NULL,
    `to_tag` VARCHAR(64) NULL,
    `from_tag` VARCHAR(64) NULL,
    `cseq` INTEGER NULL,
    `record_route` VARCHAR(191) NULL,
    `contact` VARCHAR(255) NULL,
    `remote_contact` VARCHAR(255) NULL,
    `version` INTEGER NULL,
    `extra_headers` VARCHAR(191) NULL,
    `sharing_tag` VARCHAR(32) NULL,

    INDEX `del1_idx`(`pres_uri`, `event`),
    INDEX `del2_idx`(`expires`),
    INDEX `update_idx`(`pres_uri`, `pres_id`, `flag`, `event`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `rtpproxy_sockets` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `rtpproxy_sock` VARCHAR(191) NOT NULL,
    `set_id` INTEGER NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `subscriber` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `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) NULL,
    `acls` VARCHAR(32) NOT NULL DEFAULT '',
    `cfaw_uri` VARCHAR(255) NULL,
    `cfbs_uri` VARCHAR(255) NULL,
    `cfna_uri` VARCHAR(255) NULL,
    `cfnf_uri` VARCHAR(255) NULL,

    INDEX `username_idx`(`username`),
    UNIQUE INDEX `subscriber_username_domain_key`(`username`, `domain`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `uri` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(64) NOT NULL,
    `domain` VARCHAR(64) NOT NULL,
    `uri_user` VARCHAR(64) NOT NULL,
    `last_modified` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    UNIQUE INDEX `uri_username_domain_uri_user_key`(`username`, `domain`, `uri_user`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `usr_preferences` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `uuid` VARCHAR(64) NOT NULL,
    `username` VARCHAR(64) NOT NULL DEFAULT '0',
    `domain` VARCHAR(64) NOT NULL,
    `attribute` VARCHAR(32) NOT NULL,
    `type` INTEGER NOT NULL DEFAULT 0,
    `value` VARCHAR(128) NOT NULL,
    `last_modified` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `ua_idx`(`uuid`, `attribute`),
    INDEX `uda_idx`(`username`, `domain`, `attribute`),
    INDEX `value_idx`(`value`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `version` (
    `table_name` VARCHAR(32) NOT NULL,
    `table_version` INTEGER NOT NULL DEFAULT 0,

    UNIQUE INDEX `version_table_name_key`(`table_name`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `watchers` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `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` INTEGER NOT NULL,
    `reason` VARCHAR(64) NULL,
    `inserted_time` INTEGER NOT NULL,

    UNIQUE INDEX `watchers_presentity_uri_watcher_username_watcher_domain_even_key`(`presentity_uri`, `watcher_username`, `watcher_domain`, `event`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `xcap` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(64) NOT NULL,
    `domain` VARCHAR(64) NOT NULL,
    `doc` LONGBLOB NOT NULL,
    `doc_type` INTEGER NOT NULL,
    `etag` VARCHAR(64) NOT NULL,
    `source` INTEGER NOT NULL,
    `doc_uri` VARCHAR(255) NOT NULL,
    `port` INTEGER NOT NULL,

    INDEX `source_idx`(`source`),
    UNIQUE INDEX `xcap_username_domain_doc_type_doc_uri_key`(`username`, `domain`, `doc_type`, `doc_uri`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
