SET @current_schema := DATABASE();

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

SET @add_reward_resource_url_sql := IF(
  NOT EXISTS (
    SELECT 1
    FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'smash_egg_reward_config'
      AND column_name = 'resource_url'
  ),
  'ALTER TABLE `smash_egg_reward_config` ADD COLUMN `resource_url` varchar(512) NOT NULL DEFAULT '''' COMMENT ''资源动效/源文件URL'' AFTER `resource_type`',
  'SELECT 1'
);
PREPARE add_reward_resource_url_stmt FROM @add_reward_resource_url_sql;
EXECUTE add_reward_resource_url_stmt;
DEALLOCATE PREPARE add_reward_resource_url_stmt;

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

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

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

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