-- Purpose: Rollback user-level speed limit overrides from user_subscribe

SET @column_exists = (
  SELECT COUNT(*)
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'user_subscribe'
    AND COLUMN_NAME = 'traffic_limit'
);

SET @sql = IF(
  @column_exists = 1,
  'ALTER TABLE `user_subscribe` DROP COLUMN `traffic_limit`',
  'SELECT ''Column traffic_limit does not exist in user_subscribe table'''
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @column_exists = (
  SELECT COUNT(*)
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'user_subscribe'
    AND COLUMN_NAME = 'speed_limit'
);

SET @sql = IF(
  @column_exists = 1,
  'ALTER TABLE `user_subscribe` DROP COLUMN `speed_limit`',
  'SELECT ''Column speed_limit does not exist in user_subscribe table'''
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
