SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;
SET CHARACTER SET utf8mb4;

SET @schema_name = DATABASE();

SET @sql = IF(
    EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @schema_name AND TABLE_NAME = 'biz_food_dish' AND COLUMN_NAME = 'tags_json'),
    'SELECT 1',
    'ALTER TABLE biz_food_dish ADD COLUMN tags_json text DEFAULT NULL COMMENT ''标签JSON'' AFTER images_json'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql = IF(
    EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @schema_name AND TABLE_NAME = 'biz_food_dish' AND COLUMN_NAME = 'description_html'),
    'SELECT 1',
    'ALTER TABLE biz_food_dish ADD COLUMN description_html text DEFAULT NULL COMMENT ''富文本描述'' AFTER tags_json'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

UPDATE biz_food_dish
SET tags_json = JSON_ARRAY()
WHERE tags_json IS NULL OR tags_json = '';
