-- 创建账号组表
CREATE TABLE IF NOT EXISTS `account_group` (
    `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `user_id` BIGINT NOT NULL COMMENT '用户ID，关联sys_user表',
    `group_name` VARCHAR(100) NOT NULL COMMENT '账号组名称',
    `delivery_mode` TINYINT NOT NULL COMMENT '投放模式：1-线索-企微-加企微，2-用户增长-短剧-注册变现ROI',
    `remark` VARCHAR(500) DEFAULT NULL COMMENT '备注信息',
    `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除标识：0-未删除，1-已删除',
    PRIMARY KEY (`id`),
    KEY `idx_user_id` (`user_id`),
    KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='账号组表';

-- 创建账号组与账号关系表
CREATE TABLE IF NOT EXISTS `account_group_account_relationship` (
    `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `group_id` BIGINT NOT NULL COMMENT '账号组ID，关联account_group表',
    `account_id` BIGINT NOT NULL COMMENT '腾讯账户ID，关联tencent_account表',
    `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    PRIMARY KEY (`id`),
    UNIQUE KEY `uk_group_account` (`group_id`, `account_id`),
    KEY `idx_group_id` (`group_id`),
    KEY `idx_account_id` (`account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='账号组与账号关系表';
