DROP TRIGGER IF EXISTS `tg_account_menu`;

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

ALTER TABLE `omc_db`.`user` 
DROP INDEX IF EXISTS `account_id`,
DROP INDEX IF EXISTS `idx_uni_user_acc_id`,
ADD UNIQUE INDEX `idx_uni_user_acc_id`(`account_id`) USING BTREE;

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

ALTER TABLE `omc_db`.`user` 
MODIFY COLUMN `password_expiration` date NULL DEFAULT NULL AFTER `change_password_flag`,
MODIFY COLUMN `user_expiration` date NULL DEFAULT NULL AFTER `status`;

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

ALTER TABLE `omc_db`.`nbi_operation_log` 
MODIFY COLUMN `created_at` datetime NULL DEFAULT NULL AFTER `log_time`;

ALTER TABLE `omc_db`.`permission` 
ADD COLUMN IF NOT EXISTS `management` varchar(32) NULL DEFAULT '*' AFTER `method`;

ALTER TABLE `omc_db`.`permission` 
CHANGE COLUMN IF EXISTS `create_at` `created_at` datetime NULL DEFAULT current_timestamp AFTER `description`,
MODIFY COLUMN `method` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '*' AFTER `permission_name`,
MODIFY COLUMN `management` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '*' AFTER `method`,
MODIFY COLUMN `element` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '*' AFTER `management`,
MODIFY COLUMN `object` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '*' AFTER `element`,
ADD COLUMN IF NOT EXISTS `updated_at` datetime NULL AFTER `created_at`,
ADD COLUMN IF NOT EXISTS `deleted_at` datetime NULL AFTER `updated_at`;

ALTER TABLE `omc_db`.`permission` 
ADD UNIQUE INDEX IF NOT EXISTS `permission_name`(`permission_name`) USING BTREE;

ALTER TABLE `omc_db`.`alarm_log` 
ADD COLUMN IF NOT EXISTS `alarm_seq` int NULL AFTER `ne_id`;

ALTER TABLE `omc_db`.`ne_software` 
ADD COLUMN IF NOT EXISTS `patch_time` datetime NULL AFTER `update_time`;

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

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

ALTER TABLE `omc_db`.`user` 
MODIFY COLUMN `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL AFTER `account_id`;

ALTER TABLE `omc_db`.`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 `omc_db`.`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 `omc_db`.`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`;

ALTER TABLE `omc_db`.`u_auth_user` ENGINE = InnoDB;
ALTER TABLE `omc_db`.`u_sub_user` ENGINE = InnoDB;

INSERT IGNORE INTO `omc_db`.`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 `omc_db`.`security_log` 
MODIFY COLUMN `id` int(10) NOT NULL AUTO_INCREMENT FIRST;

ALTER TABLE `omc_db`.`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 `omc_db`.`trace_data` 
MODIFY COLUMN `timestamp` bigint NULL DEFAULT NULL AFTER `msg_direct`;

ALTER TABLE `omc_db`.`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 `omc_db`.`ne_license` 
MODIFY COLUMN `status` enum('ACTIVE','INACTIVE','PENDING') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'ACTIVE' AFTER `expiration_date`,
ADD COLUMN IF NOT EXISTS `path` varchar(128) NULL AFTER `status`,
ADD COLUMN IF NOT EXISTS `file_name` varchar(64) NULL AFTER `path`,
ADD COLUMN IF NOT EXISTS `comment` varchar(255) NULL AFTER `file_name`;

DELETE FROM ne_license WHERE file_name IS NULL;

ALTER TABLE `omc_db`.`trace_data` 
ADD COLUMN IF NOT EXISTS `length` int NULL AFTER `msg_direct`;

-- UDM签约存储长度不足
ALTER TABLE `omc_db`.`u_sub_user` 
MODIFY COLUMN `sm_data` varchar(1500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'smData' AFTER `cn`,
MODIFY COLUMN `eps_dat` varchar(1500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'Eps' AFTER `smf_sel`;

ALTER TABLE
    `omc_db`.`ne_backup`
ADD
    COLUMN IF NOT EXISTS `comment` varchar(255) NULL AFTER `md5_sum`;

ALTER TABLE
    `omc_db`.`sys_dict_data` MODIFY COLUMN `dict_label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '字典标签' AFTER `dict_sort`,
    MODIFY COLUMN `dict_value` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '字典键值' AFTER `dict_label`;

ALTER TABLE
    `omc_db`.`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 `omc_db`.`mml_command`
SET `status` = 'Inactive'
WHERE
    `category` = 'licenseManagement';

ALTER TABLE
    `omc_db`.`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
    `omc_db`.`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
    `omc_db`.`system_log`
ADD
    COLUMN IF NOT EXISTS `operation` varchar(16) NULL AFTER `process_id`;

UPDATE ne_info SET `province` = '-' WHERE `province` = 'GD';

UPDATE ne_info
SET
    `vendor_name` = "AGrandTech"
WHERE `vendor_name` = "AGT";

UPDATE ne_info SET `dn` = "-" WHERE `dn` = "TN";

ALTER TABLE
    `omc_db`.`sys_dept` MODIFY COLUMN `dept_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '部门名称' AFTER `ancestors`;

ALTER TABLE `omc_db`.`sys_dict_data`
MODIFY COLUMN `dict_code` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '字典编码' FIRST;

ALTER TABLE `omc_db`.`gold_kpi`
ADD COLUMN IF NOT EXISTS `granularity` tinyint NULL DEFAULT 60 COMMENT '时间颗粒度: 5/10/.../60/300 (秒)' AFTER `index`;

ALTER TABLE `omc_db`.`ne_info`
DROP PRIMARY KEY,
ADD PRIMARY KEY (`id`) USING BTREE;

ALTER TABLE `omc_db`.`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 `omc_db`.`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 `omc_db`.`gold_kpi`
ADD INDEX IF NOT EXISTS `idx_date` (`date`) USING BTREE;

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

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

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

REPLACE INTO
    `omc_db`.`sys_dict_data`
VALUES (
        4034, 4034, 'menu.dashboard.overview', 'Overview', 'i18n_en', NULL, NULL, '1', 'supervisor', 1705550000000, NULL, 0, NULL
    );

ALTER TABLE `omc_db`.`alarm`
ADD INDEX IF NOT EXISTS `idx_severity_status` (
    `alarm_status`, `orig_severity`
) USING BTREE;

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

-- 性能数据文件的上报
INSERT IGNORE INTO `sys_job` (`job_name`, `job_group`, `invoke_target`, `target_params`, `cron_expression`, `misfire_policy`, `concurrent`, `status`, `save_log`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES ('job.nms_cxy.performance_upload_oss', 'SYSTEM', 'performance_upload_oss', '{\"interval\":15,\"neTypes\":[\"AMF\",\"UPF\"]}', '0 0/15 * * * ?', '3', '0', '1', '1', 'supervisor', 1698478134839, 'supervisor', 1710817306404, 'job.nms_cxy.performance_upload_oss_remark');
INSERT IGNORE INTO `sys_dict_data` VALUES (210, 210, 'job.nms_cxy.performance_upload_oss', '性能数据文件的上报', 'i18n_zh', '', '', '1', 'supervisor', 1705550000000, '', 0, '');
INSERT IGNORE INTO `sys_dict_data` VALUES (211, 211, 'job.nms_cxy.performance_upload_oss_remark', 'interval周期为15分钟。neTypes为数组对应上报数据的网元类型。', 'i18n_zh', '', '', '1', 'supervisor', 1705550000000, '', 0, '');
INSERT IGNORE INTO `sys_dict_data` VALUES (212, 212, 'job.nms_cxy.performance_upload_oss', 'Reporting of performance data files', 'i18n_en', '', '', '1', 'supervisor', 1705550000000, '', 0, '');
INSERT IGNORE INTO `sys_dict_data` VALUES (213, 213, 'job.nms_cxy.performance_upload_oss_remark', 'The interval period is 15 minutes. neTypes is an array corresponding to the type of network element for which the data was reported.', 'i18n_en', '', '', '1', 'supervisor', 1705550000000, '', 0, '');

-- 资源数据上报接口
INSERT IGNORE INTO `sys_job` (`job_name`, `job_group`, `invoke_target`, `target_params`, `cron_expression`, `misfire_policy`, `concurrent`, `status`, `save_log`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES ('job.nms_cxy.resource_upload_oss', 'SYSTEM', 'resource_upload_oss', '{\"interval\":15}', '0 0 0,12 * * ?', '3', '0', '1', '1', 'supervisor', 1698478134839, 'supervisor', 1710818082110, 'job.nms_cxy.resource_upload_oss_remark');
INSERT IGNORE INTO `sys_dict_data` VALUES (215, 215, 'job.nms_cxy.resource_upload_oss', '资源数据上报接口', 'i18n_zh', '', '', '1', 'supervisor', 1705550000000, '', 0, '');
INSERT IGNORE INTO `sys_dict_data` VALUES (216, 216, 'job.nms_cxy.resource_upload_oss_remark', '每天的 0 时及 12 时上报网元的全量资源数据文件至 OSS。', 'i18n_zh', '', '', '1', 'supervisor', 1705550000000, '', 0, '');
INSERT IGNORE INTO `sys_dict_data` VALUES (217, 217, 'job.nms_cxy.resource_upload_oss', 'Resource data reporting interface', 'i18n_en', '', '', '1', 'supervisor', 1705550000000, '', 0, '');
INSERT IGNORE INTO `sys_dict_data` VALUES (218, 218, 'job.nms_cxy.resource_upload_oss_remark', 'Full resource data files for network elements are reported to the OSS at 0000 and 1200 hours each day.', 'i18n_en', '', '', '1', 'supervisor', 1705550000000, '', 0, '');

