SET @table_schema = DATABASE();

CREATE TABLE IF NOT EXISTS `team_manager_base_info` (
  `id` bigint NOT NULL COMMENT '主键ID',
  `sys_origin` varchar(64) NOT NULL DEFAULT '' COMMENT '来源APP',
  `user_id` bigint NOT NULL COMMENT '经理用户ID',
  `contact` varchar(255) NOT NULL DEFAULT '' COMMENT '联系方式',
  `region_id` varchar(64) NOT NULL DEFAULT '' COMMENT '区域ID',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `create_user` bigint DEFAULT NULL COMMENT '创建人',
  `update_user` bigint DEFAULT NULL COMMENT '更新人',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_team_manager_user_id` (`user_id`),
  KEY `idx_team_manager_sys_origin` (`sys_origin`),
  KEY `idx_team_manager_region` (`region_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='团队经理基本信息';

SET @ddl = IF(
    EXISTS(
        SELECT 1
        FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @table_schema
          AND TABLE_NAME = 'user_history_identity'
          AND COLUMN_NAME = 'is_manager'
    ),
    'SELECT 1',
    "ALTER TABLE `user_history_identity` ADD COLUMN `is_manager` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否做过团队经理' AFTER `is_host`"
);
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
