SET @current_schema := DATABASE();

SET @add_provider_lucky_gift_url_sql := IF(
  NOT EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_schema = @current_schema
      AND table_name = 'baishun_provider_config'
      AND column_name = 'lucky_gift_url'
  ),
  'ALTER TABLE `baishun_provider_config` ADD COLUMN `lucky_gift_url` varchar(1024) NOT NULL DEFAULT '''' AFTER `game_list_url`',
  'SELECT 1'
);
PREPARE add_provider_lucky_gift_url_stmt FROM @add_provider_lucky_gift_url_sql;
EXECUTE add_provider_lucky_gift_url_stmt;
DEALLOCATE PREPARE add_provider_lucky_gift_url_stmt;

UPDATE `baishun_provider_config`
SET `lucky_gift_url` = CONCAT(TRIM(TRAILING '/' FROM `platform_base_url`), '/lucky_gift/start_game')
WHERE COALESCE(TRIM(`lucky_gift_url`), '') = ''
  AND COALESCE(TRIM(`platform_base_url`), '') <> '';
