SET @column_exists := (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'la_match_live'
      AND COLUMN_NAME = 'anchor_id'
);
SET @sql := IF(
    @column_exists = 0,
    'ALTER TABLE `la_match_live` ADD COLUMN `anchor_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT ''主播ID'' AFTER `source_match_time`',
    'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @column_exists := (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'la_match_live'
      AND COLUMN_NAME = 'anchor_name'
);
SET @sql := IF(
    @column_exists = 0,
    'ALTER TABLE `la_match_live` ADD COLUMN `anchor_name` varchar(100) NOT NULL DEFAULT '''' COMMENT ''主播昵称'' AFTER `anchor_id`',
    'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @column_exists := (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'la_match_live'
      AND COLUMN_NAME = 'anchor_avatar'
);
SET @sql := IF(
    @column_exists = 0,
    'ALTER TABLE `la_match_live` ADD COLUMN `anchor_avatar` varchar(500) NOT NULL DEFAULT '''' COMMENT ''主播头像'' AFTER `anchor_name`',
    'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @column_exists := (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'la_match_live'
      AND COLUMN_NAME = 'anchor_level'
);
SET @sql := IF(
    @column_exists = 0,
    'ALTER TABLE `la_match_live` ADD COLUMN `anchor_level` varchar(50) NOT NULL DEFAULT '''' COMMENT ''主播等级'' AFTER `anchor_avatar`',
    'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @column_exists := (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'la_match_live'
      AND COLUMN_NAME = 'room_view_count'
);
SET @sql := IF(
    @column_exists = 0,
    'ALTER TABLE `la_match_live` ADD COLUMN `room_view_count` int UNSIGNED NOT NULL DEFAULT 0 COMMENT ''直播间观看数'' AFTER `anchor_level`',
    'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @column_exists := (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'la_match_live'
      AND COLUMN_NAME = 'room_focus_count'
);
SET @sql := IF(
    @column_exists = 0,
    'ALTER TABLE `la_match_live` ADD COLUMN `room_focus_count` int UNSIGNED NOT NULL DEFAULT 0 COMMENT ''直播间关注数'' AFTER `room_view_count`',
    'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @column_exists := (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'la_match_live'
      AND COLUMN_NAME = 'room_notice'
);
SET @sql := IF(
    @column_exists = 0,
    'ALTER TABLE `la_match_live` ADD COLUMN `room_notice` varchar(500) NOT NULL DEFAULT '''' COMMENT ''直播间公告'' AFTER `room_focus_count`',
    'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @column_exists := (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'la_match_live'
      AND COLUMN_NAME = 'room_detail'
);
SET @sql := IF(
    @column_exists = 0,
    'ALTER TABLE `la_match_live` ADD COLUMN `room_detail` varchar(255) NOT NULL DEFAULT '''' COMMENT ''直播间简介'' AFTER `room_notice`',
    'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @index_exists := (
    SELECT COUNT(*)
    FROM information_schema.STATISTICS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'la_match_live'
      AND INDEX_NAME = 'idx_anchor_id'
);
SET @sql := IF(
    @index_exists = 0,
    'ALTER TABLE `la_match_live` ADD KEY `idx_anchor_id` (`anchor_id`) USING BTREE',
    'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
