CREATE TABLE IF NOT EXISTS `accounts` (
  `id` int NOT NULL AUTO_INCREMENT,
  `account` varchar(45) DEFAULT NULL,
  `password` varchar(45) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `state` tinyint DEFAULT '0',
  `role_type` tinyint DEFAULT 0,
  `parent_account` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_account` (`account`),
  KEY `idx_parent` (`parent_account`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `accountapprels` (
  `id` int NOT NULL AUTO_INCREMENT,
  `app_key` varchar(20) DEFAULT '',
  `account` varchar(20) DEFAULT '',
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_account` (`app_key`,`account`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `androidpushconfs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `app_key` varchar(20) DEFAULT NULL,
  `push_channel` varchar(10) DEFAULT NULL,
  `package` varchar(100) DEFAULT NULL,
  `push_conf` varchar(500) DEFAULT NULL,
  `push_ext` MEDIUMBLOB DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_channel` (`app_key`,`push_channel`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `appexts` (
  `id` int NOT NULL AUTO_INCREMENT,
  `app_key` varchar(50) DEFAULT NULL,
  `app_item_key` varchar(50) DEFAULT NULL,
  `app_item_value` varchar(2048) DEFAULT NULL,
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE KEY `IDX_APPKEY_APPITEMKEY` (`app_key`,`app_item_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `apps` (
  `id` int NOT NULL AUTO_INCREMENT,
  `app_key` varchar(45) NOT NULL,
  `app_secret` varchar(45) NOT NULL,
  `app_secure_key` varchar(45) NOT NULL,
  `app_status` tinyint DEFAULT '0',
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `license` text,
  `lic_conf` text,
  `app_type` tinyint DEFAULT '0',
  `app_name` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_appkey` (`app_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `banusers` (
  `id` int NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) NOT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `end_time` bigint DEFAULT '0',
  `scope_key` varchar(20) NOT NULL DEFAULT 'default',
  `scope_value` varchar(1000) DEFAULT '',
  `ext` varchar(100) DEFAULT NULL,
  `app_key` varchar(20) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_appkey_userid` (`app_key`,`user_id`,`scope_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `bc_hismsgs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `conver_id` varchar(100) NOT NULL,
  `sender_id` varchar(32) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `msg_type` varchar(50) DEFAULT NULL,
  `msg_id` varchar(20) NOT NULL,
  `send_time` bigint DEFAULT NULL,
  `msg_seq_no` int DEFAULT NULL,
  `msg_body` mediumblob,
  `app_key` varchar(20) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_msgid` (`app_key`,`conver_id`,`msg_id`,`send_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `blocks` (
  `id` int NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `block_user_id` varchar(32) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_appkey_userid` (`app_key`,`user_id`,`block_user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `brdinboxmsgs` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `sender_id` varchar(32) DEFAULT NULL,
  `send_time` bigint DEFAULT NULL,
  `msg_id` varchar(20) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `msg_body` mediumblob,
  `app_key` varchar(32) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_sendtime` (`app_key`,`send_time`),
  KEY `idx_msg_id` (`app_key`,`msg_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `chatroominfos` (
  `id` int NOT NULL AUTO_INCREMENT,
  `chat_id` varchar(32) DEFAULT NULL,
  `chat_name` varchar(45) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_chatid` (`app_key`,`chat_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `cmdinboxmsgs` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `send_time` bigint DEFAULT NULL,
  `msg_id` varchar(20) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `msg_body` mediumblob,
  `app_key` varchar(20) DEFAULT NULL,
  `target_id` varchar(32) DEFAULT NULL,
  `msg_type` varchar(50) DEFAULT NULL,
  `uniq_tag` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_tag` (`app_key`,`user_id`,`uniq_tag`),
  KEY `idx_appkey_time` (`app_key`,`user_id`,`send_time`),
  KEY `idx_msg_id` (`app_key`,`user_id`,`msg_id`),
  KEY `idx_appkey` (`app_key`,`send_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `cmdsendboxmsgs` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `send_time` bigint DEFAULT NULL,
  `msg_id` varchar(20) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `msg_body` mediumblob,
  `app_key` varchar(20) DEFAULT NULL,
  `target_id` varchar(32) DEFAULT NULL,
  `msg_type` varchar(50) DEFAULT NULL,
  `uniq_tag` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_tag` (`app_key`,`user_id`,`uniq_tag`),
  KEY `idx_appkey_userid_time` (`app_key`,`user_id`,`send_time`),
  KEY `idx_msg_id` (`app_key`,`user_id`,`msg_id`),
  KEY `idx_appkey` (`app_key`,`send_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `convercleantimes` (
  `id` int NOT NULL AUTO_INCREMENT,
  `conver_id` varchar(100) DEFAULT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `channel_type` tinyint DEFAULT '0',
  `clean_time` bigint DEFAULT '0',
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_destroy` (`app_key`,`conver_id`,`sub_channel`,`channel_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `conversations` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `target_id` varchar(32) DEFAULT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `channel_type` tinyint DEFAULT '0',
  `latest_msg_id` varchar(20) DEFAULT NULL,
  `latest_msg` mediumblob,
  `latest_unread_msg_index` int DEFAULT '0',
  `latest_read_msg_index` int DEFAULT '0',
  `latest_read_msg_id` varchar(20) DEFAULT NULL,
  `latest_read_msg_time` bigint DEFAULT '0',
  `sort_time` bigint DEFAULT '0',
  `is_deleted` tinyint DEFAULT '0',
  `is_top` tinyint DEFAULT '0',
  `top_updated_time` bigint DEFAULT '0',
  `undisturb_type` tinyint DEFAULT '0',
  `sync_time` bigint DEFAULT '0',
  `unread_tag` tinyint DEFAULT '0',
  `conver_exts` mediumblob,
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_app_key_user_id_target_id` (`app_key`,`user_id`,`target_id`,`sub_channel`,`channel_type`),
  KEY `idx_sync_time` (`app_key`,`user_id`,`sync_time`),
  KEY `idx_update_time` (`app_key`,`user_id`,`sort_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `userconvertags` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `user_id` VARCHAR(32) NULL,
  `tag` VARCHAR(50) NULL,
  `tag_name` VARCHAR(50) NULL,
  `tag_order` INT NULL DEFAULT 0,
  `created_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_tag` (`app_key`, `user_id`, `tag`),
  INDEX `idx_tag` (`app_key`, `user_id`, `tag_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `convertagrels` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `user_id` VARCHAR(32) NULL,
  `tag` VARCHAR(50) NULL,
  `target_id` VARCHAR(32) NULL,
  `channel_type` TINYINT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `created_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_tag_target` (`app_key`, `user_id`, `tag`, `target_id`, `channel_type`, `sub_channel`),
  KEY `idx_target` (`app_key`, `user_id`, `target_id`, `channel_type`, `sub_channel`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `msgstats` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `stat_type` TINYINT NULL DEFAULT 0,
  `channel_type` TINYINT NULL,
  `time_mark` BIGINT NULL,
  `count` INT NULL,
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_mark` (`app_key` ASC, `stat_type` ASC, `channel_type` ASC, `time_mark` ASC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `useractivities` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `user_id` VARCHAR(32) NULL,
  `time_mark` BIGINT NULL,
  `created_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
  `count` INT NULL,
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_userid` (`app_key` ASC, `time_mark` ASC, `user_id` ASC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `connectcounts` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `connect_type` TINYINT NULL DEFAULT 0,
  `time_mark` BIGINT NULL,
  `count` INT NULL,
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_mark` (`app_key`, `connect_type`, `time_mark`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `fileconfs` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `app_key` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `channel` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `conf` json DEFAULT NULL,
  `enable` tinyint(1) DEFAULT '0',
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE KEY `app_key` (`app_key`,`channel`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

CREATE TABLE IF NOT EXISTS `g_delhismsgs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `target_id` varchar(32) DEFAULT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `msg_id` varchar(20) DEFAULT NULL,
  `msg_time` bigint DEFAULT 0,
  `msg_seq` int DEFAULT 0,
  `effective_time` bigint DEFAULT 0,
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_msgid` (`app_key`,`user_id`,`target_id`,`sub_channel`,`msg_id`),
  KEY `idx_target` (`app_key`,`user_id`,`target_id`,`sub_channel`,`msg_time`),
  KEY `idx_appkey_time` (`app_key`,`msg_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `g_hismsgs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `conver_id` varchar(100) DEFAULT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `sender_id` varchar(32) DEFAULT NULL,
  `receiver_id` varchar(32) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `msg_type` varchar(50) DEFAULT NULL,
  `msg_id` varchar(20) DEFAULT NULL,
  `send_time` bigint DEFAULT NULL,
  `msg_seq_no` int DEFAULT NULL,
  `msg_body` mediumblob,
  `original_msg_body` mediumblob,
  `app_key` varchar(20) DEFAULT NULL,
  `member_count` int DEFAULT '0',
  `read_count` int DEFAULT '0',
  `is_delete` tinyint DEFAULT '0',
  `is_ext` tinyint DEFAULT '0',
  `is_exset` tinyint DEFAULT '0',
  `msg_ext` mediumblob,
  `msg_exset` mediumblob,
  `destroy_time` bigint DEFAULT 0,
  `life_time_after_read` bigint DEFAULT 0,
  `is_portion` tinyint DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `idx_appkey_converid` (`app_key`,`conver_id`,`sub_channel`,`msg_id`,`send_time`),
  KEY `idx_conver_time` (`app_key`,`conver_id`,`sub_channel`,`send_time`),
  KEY `idx_sender_time` (`app_key`,`conver_id`,`sub_channel`,`sender_id`,`send_time`),
  KEY `idx_appkey_time` (`app_key`,`send_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `g_portionrels` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `conver_id` VARCHAR(100) NULL,
  `sub_channel` VARCHAR(32) NULL DEFAULT '',
  `channel_type` TINYINT NULL DEFAULT 0,
  `user_id` VARCHAR(32) NULL,
  `msg_id` VARCHAR(32) NULL,
  `msg_time` BIGINT NULL DEFAULT 0,
  `app_key` VARCHAR(20) NULL DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_msgid` (`app_key`, `conver_id`, `sub_channel`, `user_id`, `msg_id`),
  INDEX `idx_msg_time` (`app_key`, `conver_id`, `sub_channel`, `user_id`, `msg_time`),
  KEY `idx_appkey_time` (`app_key`,`msg_time`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `c_hismsgs` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `conver_id` VARCHAR(100) NULL,
  `sender_id` VARCHAR(32) NULL,
  `receiver_id` VARCHAR(32) NULL,
  `channel_type` TINYINT NULL,
  `msg_type` VARCHAR(50) NULL,
  `msg_id` VARCHAR(20) NULL,
  `send_time` BIGINT NULL,
  `msg_seq_no` INT NULL,
  `msg_body` MEDIUMBLOB NULL,
  `original_msg_body` mediumblob NULL,
  `member_count` INT NULL,
  `is_delete` TINYINT NULL,
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  INDEX `idx_conver` (`app_key`, `conver_id`, `msg_id`, `send_time`),
  INDEX `idx_conver_time` (`app_key`, `conver_id`, `send_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `gc_hismsgs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `conver_id` varchar(100) DEFAULT NULL,
  `sender_id` varchar(32) DEFAULT NULL,
  `receiver_id` varchar(32) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `msg_type` varchar(50) DEFAULT NULL,
  `msg_id` varchar(20) DEFAULT NULL,
  `send_time` bigint DEFAULT NULL,
  `msg_seq_no` int DEFAULT NULL,
  `msg_body` mediumblob,
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_msg` (`app_key`,`conver_id`,`channel_type`,`send_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `globalconfs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `conf_key` varchar(50) DEFAULT NULL,
  `conf_value` varchar(2000) DEFAULT NULL,
  `created_at` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_at` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_key` (`conf_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `globalconvers` (
  `id` int NOT NULL AUTO_INCREMENT,
  `conver_id` varchar(100) DEFAULT NULL,
  `sender_id` varchar(32) DEFAULT NULL,
  `target_id` varchar(32) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `updated_time` bigint DEFAULT NULL,
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_conver` (`app_key`,`conver_id`,`sub_channel`,`channel_type`),
  KEY `idx_time` (`app_key`,`channel_type`,`updated_time`),
  KEY `idx_targetid` (`app_key`,`channel_type`,`target_id`,`updated_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `groupinfoexts` (
  `id` int NOT NULL AUTO_INCREMENT,
  `group_id` varchar(32) DEFAULT NULL,
  `item_key` varchar(50) DEFAULT NULL,
  `item_value` varchar(1000) DEFAULT NULL,
  `item_type` tinyint DEFAULT '0',
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_appkey_groupid` (`app_key`,`group_id`,`item_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `groupinfos` (
  `id` int NOT NULL AUTO_INCREMENT,
  `group_id` varchar(64) DEFAULT NULL,
  `group_name` varchar(64) DEFAULT NULL,
  `group_portrait` varchar(200) DEFAULT NULL,
  `creator_id` varchar(64) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  `is_mute` tinyint DEFAULT '0',
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_appkey_groupid` (`app_key`,`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `groupmemberexts` (
  `id` int NOT NULL AUTO_INCREMENT,
  `group_id` varchar(32) DEFAULT NULL,
  `member_id` varchar(32) DEFAULT NULL,
  `item_key` varchar(50) DEFAULT NULL,
  `item_value` varchar(100) DEFAULT NULL,
  `item_type` tinyint DEFAULT '0',
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_item_key` (`app_key`,`group_id`,`member_id`,`item_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `groupmembers` (
  `id` int NOT NULL AUTO_INCREMENT,
  `group_id` varchar(64) DEFAULT NULL,
  `member_id` varchar(64) DEFAULT NULL,
  `member_type` tinyint DEFAULT '0',
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` varchar(45) DEFAULT NULL,
  `is_mute` tinyint DEFAULT '0',
  `is_allow` tinyint DEFAULT '0',
  `mute_end_at` bigint DEFAULT '0',
  `grp_display_name` varchar(100) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_appkey_grpid_memid` (`app_key`,`group_id`,`member_id`),
  KEY `idx_memberid` (`app_key`,`member_id`,`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `grpassistantrels` (
  `id` int NOT NULL,
  `assistant_id` varchar(32) DEFAULT NULL,
  `target_id` varchar(32) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_target` (`assistant_id`,`target_id`,`channel_type`,`app_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `grpsnapshots` (
  `id` int NOT NULL AUTO_INCREMENT,
  `app_key` varchar(20) NOT NULL,
  `group_id` varchar(32) NOT NULL,
  `created_time` bigint DEFAULT '0',
  `snapshot` mediumblob,
  PRIMARY KEY (`id`),
  KEY `idx_group_id` (`app_key`,`group_id`,`created_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `ic_conditions` (
  `id` int NOT NULL AUTO_INCREMENT,
  `channel_type` varchar(100) DEFAULT NULL,
  `msg_type` varchar(1000) DEFAULT NULL,
  `sender_id` varchar(1000) DEFAULT NULL,
  `receiver_id` varchar(1000) DEFAULT NULL,
  `interceptor_id` int DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_icid` (`app_key`,`interceptor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `inboxmsgs` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `send_time` bigint DEFAULT NULL,
  `msg_id` varchar(20) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `msg_body` mediumblob,
  `app_key` varchar(20) DEFAULT NULL,
  `target_id` varchar(32) DEFAULT NULL,
  `msg_type` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `IDX_USERID_MSG` (`app_key`,`user_id`,`send_time`),
  KEY `idx_msg_id` (`app_key`,`user_id`,`msg_id`),
  KEY `idx_appkey` (`app_key`,`send_time`)
) ENGINE=InnoDB AUTO_INCREMENT=45612 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `interceptors` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  `sort` int NOT NULL DEFAULT '0',
  `request_url` varchar(500) DEFAULT NULL,
  `request_template` text,
  `succ_template` varchar(200) DEFAULT NULL,
  `is_async` tinyint DEFAULT '0',
  `conf` varchar(2000) DEFAULT NULL,
  `intercept_type` tinyint DEFAULT '0',
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_sort` (`app_key`,`sort`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `ioscertificates` (
  `id` int NOT NULL AUTO_INCREMENT,
  `package` varchar(100) DEFAULT NULL,
  `certificate` mediumblob,
  `cert_pwd` varchar(50) DEFAULT NULL,
  `app_key` varchar(20) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `is_product` tinyint DEFAULT '0',
  `cert_path` varchar(255) DEFAULT NULL,
  `voip_cert` mediumblob,
  `voip_cert_pwd` varchar(50) DEFAULT NULL,
  `voip_cert_path` varchar(255) DEFAULT NULL,
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_package` (`app_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `mentionmsgs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `target_id` varchar(32) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `sender_id` varchar(32) DEFAULT NULL,
  `mention_type` tinyint DEFAULT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `msg_id` varchar(20) DEFAULT NULL,
  `msg_time` bigint DEFAULT NULL,
  `msg_index` int DEFAULT NULL,
  `is_read` tinyint DEFAULT NULL,
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_uid_tid_type` (`app_key`,`user_id`,`target_id`,`channel_type`,`sub_channel`,`msg_index`,`msg_time`),
  KEY `idx_read` (`app_key`,`user_id`,`target_id`,`channel_type`,`sub_channel`,`is_read`,`msg_time`),
  KEY `idx_user_msgid` (`app_key`,`user_id`,`target_id`,`channel_type`,`sub_channel`,`msg_id`),
  KEY `idx_target_msgid` (`app_key`, `msg_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `mergedmsgs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_msg_id` varchar(20) DEFAULT NULL,
  `from_id` varchar(32) DEFAULT NULL,
  `target_id` varchar(32) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `msg_id` varchar(20) DEFAULT NULL,
  `msg_time` bigint DEFAULT '0',
  `msg_body` mediumblob,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_appkey_pmsg` (`app_key`,`parent_msg_id`,`msg_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `msgexts` (
  `id` int NOT NULL AUTO_INCREMENT,
  `msg_id` varchar(20) DEFAULT NULL,
  `key` varchar(50) DEFAULT NULL,
  `value` varchar(1000) DEFAULT NULL,
  `user_id` varchar(32) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_msgid` (`app_key`,`msg_id`,`key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `msgexsets` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `msg_id` VARCHAR(20) NULL,
  `key` VARCHAR(50) NULL,
  `item` VARCHAR(100) NULL,
  `user_id` varchar(32) DEFAULT NULL,
  `created_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_item` (`app_key`, `msg_id`, `key`, `item`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `p_delhismsgs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `target_id` varchar(32) DEFAULT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `msg_id` varchar(20) DEFAULT NULL,
  `msg_time` bigint DEFAULT 0,
  `msg_seq` int DEFAULT 0,
  `effective_time` bigint DEFAULT 0,
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_msgid` (`app_key`,`user_id`,`target_id`,`sub_channel`,`msg_id`),
  KEY `idx_target` (`app_key`,`user_id`,`target_id`,`sub_channel`,`msg_time`),
  KEY `idx_appkey_time` (`app_key`,`msg_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `p_hismsgs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `conver_id` varchar(100) DEFAULT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `sender_id` varchar(32) DEFAULT NULL,
  `receiver_id` varchar(32) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `msg_type` varchar(50) DEFAULT NULL,
  `msg_id` varchar(20) DEFAULT NULL,
  `send_time` bigint DEFAULT NULL,
  `msg_seq_no` int DEFAULT NULL,
  `msg_body` mediumblob,
  `original_msg_body` mediumblob,
  `app_key` varchar(20) DEFAULT NULL,
  `is_read` tinyint DEFAULT '0',
  `read_time` bigint DEFAULT 0,
  `is_delete` tinyint DEFAULT '0',
  `is_ext` tinyint DEFAULT '0',
  `is_exset` tinyint DEFAULT '0',
  `msg_ext` mediumblob,
  `msg_exset` mediumblob,
  `destroy_time` bigint DEFAULT 0,
  `life_time_after_read` bigint DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `idx_app_key_conver_id` (`app_key`,`conver_id`,`sub_channel`,`msg_id`,`send_time`),
  KEY `idx_conver_time` (`app_key`,`conver_id`,`sub_channel`,`send_time`),
  KEY `idx_sender_time` (`app_key`,`conver_id`,`sub_channel`,`sender_id`,`send_time`),
  KEY `idx_appkey_time` (`app_key`,`send_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `pushtokens` (
  `id` int NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `device_id` varchar(200) DEFAULT NULL,
  `platform` varchar(10) DEFAULT NULL,
  `push_channel` varchar(10) DEFAULT NULL,
  `package` varchar(200) DEFAULT NULL,
  `push_token` varchar(200) DEFAULT NULL,
  `voip_token` varchar(200) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_user_id` (`app_key`,`user_id`),
  KEY `idx_device_id` (`app_key`,`device_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `readinfos` (
  `id` int NOT NULL AUTO_INCREMENT,
  `app_key` varchar(20) NOT NULL,
  `msg_id` varchar(20) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `group_id` varchar(32) DEFAULT NULL,
  `member_id` varchar(32) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_member` (`app_key`,`channel_type`,`group_id`,`msg_id`,`member_id`,`sub_channel`),
  KEY `idx_memberid` (`app_key`,`channel_type`,`group_id`,`sub_channel`,`member_id`,`msg_id`),
  KEY `idx_msgid` (`app_key`,`channel_type`,`group_id`,`sub_channel`,`msg_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `s_hismsgs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `conver_id` varchar(100) DEFAULT NULL,
  `sender_id` varchar(32) DEFAULT NULL,
  `receiver_id` varchar(32) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `msg_type` varchar(50) DEFAULT NULL,
  `msg_id` varchar(20) DEFAULT NULL,
  `send_time` bigint DEFAULT NULL,
  `msg_seq_no` int DEFAULT NULL,
  `msg_body` mediumblob,
  `app_key` varchar(20) DEFAULT NULL,
  `is_read` tinyint DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_appkey_converid` (`app_key`,`conver_id`,`send_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `sendboxmsgs` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `send_time` bigint DEFAULT NULL,
  `msg_id` varchar(20) DEFAULT NULL,
  `channel_type` tinyint DEFAULT NULL,
  `msg_body` mediumblob,
  `app_key` varchar(20) DEFAULT NULL,
  `target_id` varchar(45) DEFAULT NULL,
  `msg_type` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_user_id_send_time` (`app_key`,`user_id`,`send_time`),
  KEY `idx_msg_id` (`app_key`,`user_id`,`msg_id`),
  KEY `idx_appkey` (`app_key`,`send_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `sensitivewords` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `app_key` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `word` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `word_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '12',
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_word` (`app_key`,`word`),
  KEY `idx_appkey` (`app_key`,`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

CREATE TABLE IF NOT EXISTS `usercleantimes` (
  `id` int NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `target_id` varchar(32) DEFAULT NULL,
  `sub_channel` varchar(32) DEFAULT '',
  `channel_type` tinyint DEFAULT NULL,
  `clean_time` bigint DEFAULT NULL,
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_app_key_user_id_target_id` (`app_key`,`user_id`,`target_id`,`sub_channel`,`channel_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `userexts` (
  `id` int NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `item_key` varchar(50) DEFAULT NULL,
  `item_value` varchar(2000) DEFAULT NULL,
  `item_type` tinyint DEFAULT '0',
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_item_key` (`app_key`,`user_id`,`item_key`),
  KEY `idx_item_key` (`app_key`,`item_key`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `users` (
  `id` int NOT NULL AUTO_INCREMENT,
  `user_type` tinyint DEFAULT '0',
  `user_id` varchar(32) NOT NULL,
  `nickname` varchar(50) DEFAULT NULL,
  `user_portrait` varchar(200) DEFAULT NULL,
  `pinyin` varchar(50) DEFAULT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  `login_account` varchar(50) DEFAULT NULL,
  `login_pass` varchar(50) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_userid` (`app_key`,`user_id`),
  UNIQUE KEY `uniq_phone` (`app_key`,`phone`),
  UNIQUE KEY `uniq_email` (`app_key`,`email`),
  UNIQUE KEY `uniq_account` (`app_key`,`login_account`),
  KEY `idx_userid` (`app_key`,`user_type`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `chatroominfos` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `chat_id` VARCHAR(32) NULL,
  `chat_name` VARCHAR(50) NULL,
  `is_mute` tinyint DEFAULT '0',
  `is_auto_destroy` tinyint DEFAULT '0',
  `created_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_chatid` (`app_key` ASC, `chat_id` ASC) VISIBLE);

  CREATE TABLE IF NOT EXISTS `chatroommembers` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `chat_id` VARCHAR(32) NULL,
  `member_id` VARCHAR(32) NULL,
  `created_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_memebrid` (`app_key` ASC, `chat_id` ASC, `member_id` ASC) VISIBLE,
  INDEX `idx_memberid` (`app_key` ASC, `member_id` ASC) VISIBLE,
  INDEX `idx_time` (`app_key` ASC, `chat_id` ASC, `created_time` ASC) VISIBLE);

  CREATE TABLE IF NOT EXISTS `chatroomexts` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `chat_id` VARCHAR(32) NULL,
  `item_key` VARCHAR(50) NULL,
  `item_value` VARCHAR(1000) NULL,
  `item_type` TINYINT NULL DEFAULT 0,
  `item_time` BIGINT NULL DEFAULT 0,
  `app_key` VARCHAR(20) NULL,
  `member_id` VARCHAR(32) NULL,
  `is_delete` TINYINT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_itemkey` (`app_key` ASC, `chat_id` ASC, `item_key` ASC) VISIBLE,
  INDEX `idx_itemkey` (`app_key` ASC, `chat_id` ASC, `item_type` ASC) VISIBLE);

  CREATE TABLE IF NOT EXISTS `chrmbanusers` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `chat_id` VARCHAR(32) NULL,
  `ban_type` TINYINT NULL,
  `member_id` VARCHAR(32) NULL,
  `end_time` BIGINT NULL DEFAULT 0,
  `created_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_memberid` (`app_key` ASC, `chat_id` ASC, `ban_type` ASC, `member_id` ASC) VISIBLE);

CREATE TABLE IF NOT EXISTS `clientlogs` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `app_key` VARCHAR(20) NULL,
  `user_id` VARCHAR(32) NULL,
  `created_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
  `start` BIGINT NULL,
  `end` BIGINT NULL,
  `log` MEDIUMBLOB NULL,
  `state` TINYINT NULL DEFAULT 0,
   `platform` VARCHAR(20) NULL,
  `device_id` VARCHAR(100) NULL,
  `log_url` VARCHAR(200) NULL,
  `trace_id` VARCHAR(50) NULL,
   `msg_id` VARCHAR(20) NULL,
  `fail_reason` VARCHAR(100) NULL,
  `description` VARCHAR(100) NULL,
  
  PRIMARY KEY (`id`),
  INDEX `idx_userid` (`app_key` ASC, `user_id` ASC),
  UNIQUE KEY `uniq_msgid` (`app_key`,`msg_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `rtcrooms` (
  `id` int NOT NULL AUTO_INCREMENT,
  `room_id` varchar(50) DEFAULT NULL,
  `room_type` tinyint DEFAULT '0',
  `rtc_channel` tinyint DEFAULT '0',
  `rtc_media_type` tinyint DEFAULT '0',
  `owner_id` varchar(32) DEFAULT NULL,
  `ext` varchar(2000) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `accepted_time` bigint DEFAULT '0',
  `conver_id` VARCHAR(100) NULL,
  `channel_type` TINYINT NULL DEFAULT 0,
  `sub_channel` VARCHAR(32) NULL DEFAULT '',
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_roomid` (`app_key`,`room_id`),
  KEY `idx_conver` (`app_key`,`conver_id`,`channel_type`,`sub_channel`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `rtcmembers` (
  `id` int NOT NULL AUTO_INCREMENT,
  `room_id` varchar(50) DEFAULT NULL,
  `member_id` varchar(32) DEFAULT NULL,
  `device_id` varchar(50) DEFAULT NULL,
  `rtc_state` tinyint DEFAULT '0',
  `inviter_id` varchar(32) DEFAULT NULL,
  `latest_ping_time` bigint DEFAULT '0',
  `call_time` bigint DEFAULT '0',
  `connect_time` bigint DEFAULT '0',
  `hangup_time` bigint DEFAULT '0',
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_member` (`app_key`,`room_id`,`member_id`),
  KEY `idx_room` (`app_key`,`member_id`,`room_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `msgtransconfs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `msg_type` varchar(50) DEFAULT NULL,
  `json_path` varchar(200) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_path` (`app_key`,`msg_type`,`json_path`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `i18nkeys` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `lang` VARCHAR(20) NULL,
  `key` VARCHAR(50) NULL,
  `value` VARCHAR(200) NULL,
  `created_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_key` (`app_key`, `lang`, `key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `friendrels` (
  `id` int NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT NULL,
  `friend_id` varchar(32) DEFAULT NULL,
  `display_name` varchar(50) DEFAULT '',
  `order_tag` varchar(20) NULL DEFAULT '',
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_friend` (`app_key`,`user_id`,`friend_id`),
  KEY `idx_order` (`app_key`, `user_id`, `order_tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `botconvers` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `conver_key` VARCHAR(100) NULL DEFAULT '',
  `conver_type` TINYINT NULL DEFAULT 0,
  `conver_id` VARCHAR(50) NULL DEFAULT '',
  `app_key` VARCHAR(50) NULL DEFAULT '',
  `updated_time` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE INDEX `uniq_key` (`app_key`, `conver_type`, `conver_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `favoritemsgs` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `user_id` VARCHAR(50) NULL,
  `sender_id` VARCHAR(50) NULL,
  `receiver_id` VARCHAR(50) NULL,
  `sub_channel` VARCHAR(32) DEFAULT '',
  `channel_type` TINYINT NULL,
  `msg_id` VARCHAR(50) NULL,
  `msg_time` BIGINT DEFAULT '0',
  `msg_type` VARCHAR(50) NULL,
  `msg_body` MEDIUMBLOB,
  `created_time` DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` VARCHAR(20) NULL,
  PRIMARY KEY (`id`),
  INDEX `idx_userid` (`app_key`, `user_id`, `created_time`),
  UNIQUE KEY `uniq_msgid` (`app_key`, `user_id`, `msg_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `topmsgs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `conver_id` varchar(100) DEFAULT '',
  `sub_channel` varchar(32) DEFAULT '',
  `channel_type` tinyint DEFAULT '0',
  `msg_id` varchar(20) DEFAULT NULL,
  `user_id` varchar(32) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_msg` (`app_key`,`conver_id`,`sub_channel`,`channel_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `pc_hismsgs` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `conver_id` varchar(100) DEFAULT '',
  `sub_channel` varchar(32) DEFAULT '',
  `channel_type` tinyint DEFAULT '0',
  `sender_id` varchar(32) DEFAULT '',
  `receiver_id` varchar(32) DEFAULT '',
  `msg_type` varchar(50) DEFAULT '',
  `msg_body` mediumblob,
  `msg_id` varchar(20) DEFAULT '',
  `send_time` bigint DEFAULT '0',
  `msg_seq_no` int DEFAULT '0',
  `app_key` varchar(20) DEFAULT '',
  `is_delete` tinyint DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `idx_msg` (`app_key`,`conver_id`,`sub_channel`,`channel_type`,`send_time`),
  KEY `idx_msgid` (`app_key`,`conver_id`,`sub_channel`,`channel_type`,`msg_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `pc_infos` (
  `id` int NOT NULL AUTO_INCREMENT,
  `channel_id` varchar(32) DEFAULT '',
  `channel_name` varchar(100) DEFAULT '',
  `channel_portrait` varchar(200) DEFAULT '',
  `creator_id` varchar(32) DEFAULT '',
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_pcid` (`app_key`,`channel_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `pc_members` (
  `id` int NOT NULL AUTO_INCREMENT,
  `channel_id` varchar(32) DEFAULT '',
  `member_id` varchar(32) DEFAULT '',
  `member_type` tinyint DEFAULT '0',
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` varchar(45) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_member` (`app_key`,`channel_id`,`member_id`),
  KEY `idx_member` (`app_key`,`channel_id`,`id`),
  KEY `idx_pcinfo` (`app_key`,`member_id`,`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `pc_gconvers` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `target_id` varchar(32) DEFAULT '',
  `channel_type` tinyint DEFAULT '0',
  `sub_channel` varchar(32) DEFAULT '',
  `latest_msg_id` varchar(32) DEFAULT '',
  `latest_unread_msg_index` int DEFAULT '0',
  `conver_time` bigint DEFAULT '0',
  `app_key` varchar(20) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_conver` (`app_key`,`target_id`,`channel_type`,`sub_channel`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `moments` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `moment_id` varchar(32) DEFAULT '',
  `title` varchar(200) DEFAULT '',
  `content` mediumblob,
  `content_brief` varchar(500) DEFAULT '',
  `moment_ext` mediumblob,
  `is_delete` tinyint DEFAULT '0',
  `user_id` varchar(32) DEFAULT '',
  `seq_no` int DEFAULT '0',
  `moment_time` bigint DEFAULT '0',
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `status` tinyint DEFAULT '0',
  `app_key` varchar(20) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_id` (`app_key`,`moment_id`),
  KEY `idx_time` (`app_key`,`moment_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `mcomments` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `comment_id` varchar(32) DEFAULT '',
  `moment_id` varchar(32) DEFAULT '',
  `parent_comment_id` varchar(32) DEFAULT '',
  `parent_user_id` varchar(32) DEFAULT '',
  `content` mediumblob,
  `is_delete` tinyint DEFAULT '0',
  `user_id` varchar(32) DEFAULT '',
  `seq_no` int DEFAULT '0',
  `comment_time` bigint DEFAULT '0',
  `updated_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `status` tinyint DEFAULT '0',
  `app_key` varchar(20) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_id` (`app_key`,`comment_id`),
  KEY `idx_time` (`app_key`,`moment_id`,`comment_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `momentfeeds` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT '',
  `moment_id` varchar(32) DEFAULT '',
  `feed_time` bigint DEFAULT '0',
  `seq_no` int DEFAULT '0',
  `app_key` varchar(20) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_moment` (`app_key`,`user_id`,`moment_id`),
  KEY `idx_time` (`app_key`,`user_id`,`feed_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `mcommentfeeds` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT '',
  `comment_id` varchar(32) DEFAULT '',
  `moment_id` varchar(32) DEFAULT '',
  `feed_time` bigint DEFAULT '0',
  `seq_no` int DEFAULT '0',
  `app_key` varchar(20) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_comment` (`app_key`,`user_id`,`moment_id`,`comment_id`),
  KEY `idx_time` (`app_key`,`user_id`,`moment_id`,`feed_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `mreactionfeeds` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT '',
  `moment_id` varchar(32) DEFAULT '',
  `reaction_key` varchar(50) DEFAULT '',
  `reaction_value` varchar(50) DEFAULT '',
  `from_user_id` varchar(32) DEFAULT '',
  `feed_time` bigint DEFAULT '0',
  `app_key` varchar(20) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_key` (`app_key`,`user_id`,`moment_id`,`reaction_key`,`from_user_id`),
  KEY `idx_time` (`app_key`,`user_id`,`moment_id`,`feed_time`),
  KEY `idx_from_user_id` (`app_key`,`moment_id`,`from_user_id`,`reaction_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `connectlogs` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `app_key` varchar(20) DEFAULT '',
  `user_id` varchar(32) DEFAULT '',
  `session_id` varchar(64) DEFAULT '',
  `connect_time` bigint DEFAULT '0',
  `disconnect_time` bigint DEFAULT '0',
  `client_ip` varchar(50) DEFAULT '',
  `client_host` varchar(100) DEFAULT '',
  `platform` varchar(20) DEFAULT '',
  `device` varchar(128) DEFAULT '',
  `device_id` varchar(256) DEFAULT '',
  `sdk_version` varchar(20) DEFAULT '',
  `is_active` tinyint DEFAULT '0',
  `connect_ext` text,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_user_session` (`app_key`,`user_id`,`session_id`),
  KEY `idx_userid` (`app_key`,`user_id`,`connect_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `binddevices` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `app_key` varchar(20) DEFAULT '',
  `user_id` varchar(32) DEFAULT '',
  `platform` varchar(20) DEFAULT '',
  `device_id` varchar(100) DEFAULT '',
  `device_company` varchar(45) DEFAULT NULL,
  `device_model` varchar(45) DEFAULT NULL,
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_deviceid` (`app_key`,`user_id`,`device_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `usersubrels` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `user_id` varchar(32) DEFAULT '',
  `subscriber_id` varchar(32) DEFAULT '',
  `subscriber_device_id` varchar(50) DEFAULT '',
  `created_time` datetime(3) DEFAULT CURRENT_TIMESTAMP(3),
  `app_key` varchar(20) DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_subscriber` (`app_key`,`user_id`,`subscriber_id`,`subscriber_device_id`),
  KEY `idx_user` (`app_key`,`subscriber_id`,`subscriber_device_id`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

INSERT IGNORE INTO `globalconfs` (`conf_key`,`conf_value`)VALUES('jimdb_version','20260508');
INSERT IGNORE INTO `accounts`(`account`,`password`)VALUES('admin','7c4a8d09ca3762af61e59520943dc26494f8941b');