DROP TRIGGER IF EXISTS `tg_account_menu`;

ALTER TABLE `gold_kpi` 
MODIFY COLUMN `value` bigint NULL DEFAULT 0 AFTER `kpi_id`;

ALTER TABLE `ne_link` DROP INDEX IF EXISTS `idx_netype_neid`;

ALTER TABLE `config` 
ADD COLUMN IF NOT EXISTS `comment` varchar(255) NULL AFTER `update_time`;

ALTER TABLE `nbi_operation_log` 
MODIFY COLUMN `created_at` datetime NULL DEFAULT NULL AFTER `log_time`;
 
ALTER TABLE `alarm_log` 
ADD COLUMN IF NOT EXISTS `alarm_seq` int NULL AFTER `ne_id`;

ALTER TABLE `nbi_alarm_log` 
ADD COLUMN IF NOT EXISTS `alarm_status` int NULL COMMENT '0/1: 清除告警/活动告警' AFTER `alarm_code`;

ALTER TABLE `cert_info` DROP INDEX IF EXISTS `idx_netype_neid`;

ALTER TABLE `measure_threshold` 
CHANGE COLUMN IF EXISTS `alarm_id` `alarm_code` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '10200' AFTER `orig_severity`;

ALTER TABLE `measure_task` 
ADD COLUMN IF NOT EXISTS `account_id` varchar(32) NULL AFTER `status`,
ADD COLUMN IF NOT EXISTS `comment` varchar(255) NULL AFTER `account_id`;

ALTER TABLE `trace_task` 
ADD COLUMN IF NOT EXISTS `account_id` varchar(32) NULL AFTER `status`,
ADD COLUMN IF NOT EXISTS `comment` varchar(255) NULL AFTER `account_id`;
 
INSERT IGNORE INTO `config` (`id`, `module_name`, `config_tag`, `title_json`, `value`, `value_json`, `comment`) 
VALUES ('37', 'System', 'logo', '{\"cn\":\"系统LOGO\",\"en\":\"System LOGO\"}', 'logo30.png', '', '');

ALTER TABLE `param_config` 
ADD COLUMN IF NOT EXISTS `method` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '*' COMMENT 'method allow: \"get\", \"get,post,put\", \"*\"' AFTER `top_display`;

DELETE FROM trace_data WHERE timestamp LIKE '2023-%';
ALTER TABLE `trace_data` 
MODIFY COLUMN `timestamp` bigint NULL DEFAULT NULL AFTER `msg_direct`;

ALTER TABLE `param_config` 
MODIFY COLUMN `method` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT 'method allow: \"get\", \"get,post,put\", \"delete\"' AFTER `top_display`;
 
ALTER TABLE `trace_data` 
ADD COLUMN IF NOT EXISTS `length` int NULL AFTER `msg_direct`;
 
ALTER TABLE
    `ne_backup`
ADD
    COLUMN IF NOT EXISTS `comment` varchar(255) NULL AFTER `md5_sum`;

ALTER TABLE
    `mml_command`
ADD
    COLUMN IF NOT EXISTS `status` enum('Active', 'Inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'Active' COMMENT '激活: Active 未激活: Inactive' AFTER `param_json`;

UPDATE `mml_command`
SET `status` = 'Inactive'
WHERE
    `category` = 'licenseManagement';

ALTER TABLE
    `mml_subscriber`
ADD
    COLUMN IF NOT EXISTS `status` enum('Active', 'Inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'Active' COMMENT '激活: Active 未激活: Inactive' AFTER `param_json`;

ALTER TABLE
    `mml_system`
ADD
    COLUMN IF NOT EXISTS `status` enum('Active', 'Inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'Active' COMMENT '激活: Active 未激活: Inactive' AFTER `param_json`;

ALTER TABLE
    `system_log`
ADD
    COLUMN IF NOT EXISTS `operation` varchar(16) NULL AFTER `process_id`;

ALTER TABLE `gold_kpi`
ADD COLUMN IF NOT EXISTS `granularity` tinyint NULL DEFAULT 60 COMMENT '时间颗粒度: 5/10/.../60/300 (秒)' AFTER `index`;
 
ALTER TABLE `gold_kpi`
ADD INDEX IF NOT EXISTS `idx_kpiid` (`kpi_id`) USING BTREE,
ADD INDEX IF NOT EXISTS `idx_timestamp` (`timestamp`) USING BTREE;

ALTER TABLE `gold_kpi`
DROP INDEX IF EXISTS `idx_st_nt_id`,
ADD INDEX IF NOT EXISTS `idx_rtds_id`(`rm_uid` ASC, `ne_type` ASC, `date` ASC, `start_time` ASC) USING BTREE;

ALTER TABLE `gold_kpi`
ADD INDEX IF NOT EXISTS `idx_date` (`date`) USING BTREE;

ALTER TABLE `gold_kpi`
ADD UNIQUE INDEX IF NOT EXISTS `idx_pk_id` (`id`) USING BTREE;

ALTER TABLE `kpi_title`
ADD INDEX IF NOT EXISTS `idx_kpi_id` (`kpi_id`) USING BTREE;

ALTER TABLE `alarm`
ADD UNIQUE INDEX IF NOT EXISTS `idx_pk_id` (`id`) USING BTREE;
 
ALTER TABLE `alarm`
ADD INDEX IF NOT EXISTS `idx_severity_status` (
    `alarm_status`, `orig_severity`
) USING BTREE;

ALTER TABLE `mml_system`
ADD COLUMN IF NOT EXISTS `object_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'mml' AFTER `mml_display`;

ALTER TABLE `ne_state`
MODIFY COLUMN `expiry_date` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '-' AFTER `serial_num`;

ALTER TABLE `alarm_forward_log`
ADD COLUMN IF NOT EXISTS `interface` varchar(16) NULL AFTER `event_time`;