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` 
DROP INDEX IF EXISTS `permission_name`,
ADD UNIQUE INDEX `permission_name`(`permission_name`) USING BTREE;

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

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

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

ALTER TABLE `omc_db`.`nbi_alarm_log` 
DROP COLUMN IF EXISTS `alarm_status`,
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`;
