SET @sys_user_theme_scheme_exists = (
    SELECT COUNT(1)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'sys_user'
      AND COLUMN_NAME = 'ui_theme_scheme'
);
SET @sys_user_theme_scheme_sql = IF(
    @sys_user_theme_scheme_exists = 0,
    'ALTER TABLE sys_user ADD COLUMN ui_theme_scheme VARCHAR(16) NULL AFTER ui_density',
    'SELECT 1'
);
PREPARE stmt_sys_user_theme_scheme FROM @sys_user_theme_scheme_sql;
EXECUTE stmt_sys_user_theme_scheme;
DEALLOCATE PREPARE stmt_sys_user_theme_scheme;

SET @platform_user_theme_scheme_exists = (
    SELECT COUNT(1)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'platform_user'
      AND COLUMN_NAME = 'ui_theme_scheme'
);
SET @platform_user_theme_scheme_sql = IF(
    @platform_user_theme_scheme_exists = 0,
    'ALTER TABLE platform_user ADD COLUMN ui_theme_scheme VARCHAR(16) NULL AFTER ui_density',
    'SELECT 1'
);
PREPARE stmt_platform_user_theme_scheme FROM @platform_user_theme_scheme_sql;
EXECUTE stmt_platform_user_theme_scheme;
DEALLOCATE PREPARE stmt_platform_user_theme_scheme;

UPDATE sys_user
SET ui_theme_scheme = IFNULL(NULLIF(UPPER(ui_theme_scheme), ''), 'SLATE')
WHERE is_deleted = 0;

UPDATE platform_user
SET ui_theme_scheme = IFNULL(NULLIF(UPPER(ui_theme_scheme), ''), 'SLATE')
WHERE is_deleted = 0;
