SET @current_schema := DATABASE();

SET @add_provider_game_list_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 = 'game_list_url'
  ),
  'ALTER TABLE `baishun_provider_config` ADD COLUMN `game_list_url` varchar(1024) NOT NULL DEFAULT '''' AFTER `platform_base_url`',
  'SELECT 1'
);
PREPARE add_provider_game_list_url_stmt FROM @add_provider_game_list_url_sql;
EXECUTE add_provider_game_list_url_stmt;
DEALLOCATE PREPARE add_provider_game_list_url_stmt;

UPDATE `baishun_provider_config`
SET `game_list_url` = CONCAT(TRIM(TRAILING '/' FROM `platform_base_url`), '/v1/api/gamelist')
WHERE COALESCE(TRIM(`game_list_url`), '') = ''
  AND COALESCE(TRIM(`platform_base_url`), '') <> '';
