SET NAMES utf8mb4;

SET @table_schema = DATABASE();
SET @ddl = IF(
    EXISTS(
        SELECT 1
        FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @table_schema
          AND TABLE_NAME = 'sys_country_code'
          AND COLUMN_NAME = 'alias_codes'
    ),
    'SELECT 1',
    "ALTER TABLE `sys_country_code` ADD COLUMN `alias_codes` varchar(255) NOT NULL DEFAULT '' COMMENT '国家code别名集合(JSON数组)' AFTER `alias_name`"
);
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

UPDATE `sys_country_code`
SET `alias_codes` = '["SA","KSA"]'
WHERE `alpha_two` = 'SA' OR `alpha_three` = 'KSA';
