SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for cdr_event_sgwc
-- ----------------------------
CREATE TABLE IF NOT EXISTS `cdr_event_sgwc`  (
  `id` int NOT NULL AUTO_INCREMENT,
  `ne_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `ne_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `rm_uid` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `timestamp` bigint(20) NULL DEFAULT NULL,
  `cdr_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  `created_at` datetime NULL DEFAULT current_timestamp(),
  `tenant_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  KEY `id` (`id`) USING BTREE,
  KEY `idx_cdr_sgwc_uid_at` (`rm_uid`,`timestamp`,`created_at`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='CDR事件_SGWC';

ALTER TABLE `cdr_event_sgwc` ADD COLUMN IF NOT EXISTS `tenant_id` varchar(32) NULL AFTER `created_at`,
DROP INDEX IF EXISTS `idx_type_timestamp`,
ADD INDEX IF NOT EXISTS `idx_cdr_sgwc_uid_at`(`rm_uid`,`timestamp`,`created_at`) USING BTREE;

SET FOREIGN_KEY_CHECKS = 1;
