SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for share_code_log
-- 分享码流水：记录导出/导入操作及 EQ 数据快照
-- ----------------------------
DROP TABLE IF EXISTS `share_code_log`;
CREATE TABLE `share_code_log` (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
  `mac_addr` varchar(17) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '设备 MAC 地址，如 AA:BB:CC:DD:EE:FF',
  `share_code` char(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '分享码（5位字符）',
  `action` enum('export','import') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '操作类型：export=导出分享码，import=导入分享码',
  `ip_addr` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '用户 IP 地址（支持 IPv4/IPv6）',
  `eq_data` json NOT NULL COMMENT 'EQ 数据快照（JSON）',
  `expire_at` datetime NULL DEFAULT NULL COMMENT '分享码到期时间（导出时快照，导入可为空）',
  `create_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '操作时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_mac_addr` (`mac_addr` ASC) USING BTREE,
  INDEX `idx_share_code` (`share_code` ASC) USING BTREE,
  INDEX `idx_create_at` (`create_at` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC COMMENT = '分享码流水表';

SET FOREIGN_KEY_CHECKS = 1;
