SET @current_schema := DATABASE();

SET @add_wheel_reward_resource_id_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_reward_config'
      AND column_name = 'resource_id'
  ),
  'ALTER TABLE `wheel_reward_config` ADD COLUMN `resource_id` bigint DEFAULT NULL COMMENT ''资源ID'' AFTER `reward_type`',
  'SELECT 1'
);
PREPARE add_wheel_reward_resource_id_stmt FROM @add_wheel_reward_resource_id_sql;
EXECUTE add_wheel_reward_resource_id_stmt;
DEALLOCATE PREPARE add_wheel_reward_resource_id_stmt;

SET @add_wheel_reward_resource_type_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_reward_config'
      AND column_name = 'resource_type'
  ),
  'ALTER TABLE `wheel_reward_config` ADD COLUMN `resource_type` varchar(64) NOT NULL DEFAULT '''' COMMENT ''资源类型'' AFTER `resource_id`',
  'SELECT 1'
);
PREPARE add_wheel_reward_resource_type_stmt FROM @add_wheel_reward_resource_type_sql;
EXECUTE add_wheel_reward_resource_type_stmt;
DEALLOCATE PREPARE add_wheel_reward_resource_type_stmt;

SET @add_wheel_reward_resource_name_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_reward_config'
      AND column_name = 'resource_name'
  ),
  'ALTER TABLE `wheel_reward_config` ADD COLUMN `resource_name` varchar(255) NOT NULL DEFAULT '''' COMMENT ''资源名称快照'' AFTER `resource_type`',
  'SELECT 1'
);
PREPARE add_wheel_reward_resource_name_stmt FROM @add_wheel_reward_resource_name_sql;
EXECUTE add_wheel_reward_resource_name_stmt;
DEALLOCATE PREPARE add_wheel_reward_resource_name_stmt;

SET @add_wheel_reward_resource_url_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_reward_config'
      AND column_name = 'resource_url'
  ),
  'ALTER TABLE `wheel_reward_config` ADD COLUMN `resource_url` varchar(512) NOT NULL DEFAULT '''' COMMENT ''资源动效URL快照'' AFTER `resource_name`',
  'SELECT 1'
);
PREPARE add_wheel_reward_resource_url_stmt FROM @add_wheel_reward_resource_url_sql;
EXECUTE add_wheel_reward_resource_url_stmt;
DEALLOCATE PREPARE add_wheel_reward_resource_url_stmt;

SET @add_wheel_reward_duration_days_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_reward_config'
      AND column_name = 'duration_days'
  ),
  'ALTER TABLE `wheel_reward_config` ADD COLUMN `duration_days` int NOT NULL DEFAULT 0 COMMENT ''资源有效天数'' AFTER `cover_url`',
  'SELECT 1'
);
PREPARE add_wheel_reward_duration_days_stmt FROM @add_wheel_reward_duration_days_sql;
EXECUTE add_wheel_reward_duration_days_stmt;
DEALLOCATE PREPARE add_wheel_reward_duration_days_stmt;

SET @add_wheel_reward_display_gold_amount_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_reward_config'
      AND column_name = 'display_gold_amount'
  ),
  'ALTER TABLE `wheel_reward_config` ADD COLUMN `display_gold_amount` bigint NOT NULL DEFAULT 0 COMMENT ''资源奖励前端展示金币价格'' AFTER `duration_days`',
  'SELECT 1'
);
PREPARE add_wheel_reward_display_gold_amount_stmt FROM @add_wheel_reward_display_gold_amount_sql;
EXECUTE add_wheel_reward_display_gold_amount_stmt;
DEALLOCATE PREPARE add_wheel_reward_display_gold_amount_stmt;

SET @add_wheel_draw_resource_id_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_draw_record'
      AND column_name = 'resource_id'
  ),
  'ALTER TABLE `wheel_draw_record` ADD COLUMN `resource_id` bigint DEFAULT NULL COMMENT ''资源ID快照'' AFTER `reward_type`',
  'SELECT 1'
);
PREPARE add_wheel_draw_resource_id_stmt FROM @add_wheel_draw_resource_id_sql;
EXECUTE add_wheel_draw_resource_id_stmt;
DEALLOCATE PREPARE add_wheel_draw_resource_id_stmt;

SET @add_wheel_draw_resource_type_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_draw_record'
      AND column_name = 'resource_type'
  ),
  'ALTER TABLE `wheel_draw_record` ADD COLUMN `resource_type` varchar(64) NOT NULL DEFAULT '''' COMMENT ''资源类型快照'' AFTER `resource_id`',
  'SELECT 1'
);
PREPARE add_wheel_draw_resource_type_stmt FROM @add_wheel_draw_resource_type_sql;
EXECUTE add_wheel_draw_resource_type_stmt;
DEALLOCATE PREPARE add_wheel_draw_resource_type_stmt;

SET @add_wheel_draw_resource_name_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_draw_record'
      AND column_name = 'resource_name'
  ),
  'ALTER TABLE `wheel_draw_record` ADD COLUMN `resource_name` varchar(255) NOT NULL DEFAULT '''' COMMENT ''资源名称快照'' AFTER `resource_type`',
  'SELECT 1'
);
PREPARE add_wheel_draw_resource_name_stmt FROM @add_wheel_draw_resource_name_sql;
EXECUTE add_wheel_draw_resource_name_stmt;
DEALLOCATE PREPARE add_wheel_draw_resource_name_stmt;

SET @add_wheel_draw_resource_url_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_draw_record'
      AND column_name = 'resource_url'
  ),
  'ALTER TABLE `wheel_draw_record` ADD COLUMN `resource_url` varchar(512) NOT NULL DEFAULT '''' COMMENT ''资源动效URL快照'' AFTER `resource_name`',
  'SELECT 1'
);
PREPARE add_wheel_draw_resource_url_stmt FROM @add_wheel_draw_resource_url_sql;
EXECUTE add_wheel_draw_resource_url_stmt;
DEALLOCATE PREPARE add_wheel_draw_resource_url_stmt;

SET @add_wheel_draw_duration_days_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_draw_record'
      AND column_name = 'duration_days'
  ),
  'ALTER TABLE `wheel_draw_record` ADD COLUMN `duration_days` int NOT NULL DEFAULT 0 COMMENT ''资源有效天数快照'' AFTER `cover_url`',
  'SELECT 1'
);
PREPARE add_wheel_draw_duration_days_stmt FROM @add_wheel_draw_duration_days_sql;
EXECUTE add_wheel_draw_duration_days_stmt;
DEALLOCATE PREPARE add_wheel_draw_duration_days_stmt;

SET @add_wheel_draw_display_gold_amount_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'wheel_draw_record'
      AND column_name = 'display_gold_amount'
  ),
  'ALTER TABLE `wheel_draw_record` ADD COLUMN `display_gold_amount` bigint NOT NULL DEFAULT 0 COMMENT ''资源奖励前端展示金币价格快照'' AFTER `duration_days`',
  'SELECT 1'
);
PREPARE add_wheel_draw_display_gold_amount_stmt FROM @add_wheel_draw_display_gold_amount_sql;
EXECUTE add_wheel_draw_display_gold_amount_stmt;
DEALLOCATE PREPARE add_wheel_draw_display_gold_amount_stmt;

UPDATE `wheel_reward_config`
SET `reward_type` = 'RESOURCE'
WHERE `reward_type` = 'RESOURCE_GROUP';

UPDATE `wheel_draw_record`
SET `reward_type` = 'RESOURCE'
WHERE `reward_type` = 'RESOURCE_GROUP';
