SET @current_schema := DATABASE();

SET @add_room_turnover_reward_auto_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'room_turnover_reward_config'
      AND column_name = 'auto_reward_enabled'
  ),
  'ALTER TABLE `room_turnover_reward_config` ADD COLUMN `auto_reward_enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT ''是否由 cron 自动发放奖励'' AFTER `enabled`',
  'SELECT 1'
);
PREPARE add_room_turnover_reward_auto_stmt FROM @add_room_turnover_reward_auto_sql;
EXECUTE add_room_turnover_reward_auto_stmt;
DEALLOCATE PREPARE add_room_turnover_reward_auto_stmt;

SET @add_room_turnover_reward_source_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'room_turnover_reward_record'
      AND column_name = 'source_id'
  ),
  'ALTER TABLE `room_turnover_reward_record` ADD COLUMN `source_id` varchar(128) DEFAULT NULL COMMENT ''Java 房间流水统计记录ID'' AFTER `track_id`',
  'SELECT 1'
);
PREPARE add_room_turnover_reward_source_stmt FROM @add_room_turnover_reward_source_sql;
EXECUTE add_room_turnover_reward_source_stmt;
DEALLOCATE PREPARE add_room_turnover_reward_source_stmt;
