USE `data_center_new`;

DROP procedure IF EXISTS `add_column`;

DELIMITER $$

CREATE PROCEDURE add_column()

BEGIN
    IF NOT EXISTS (
        SELECT * 
        FROM information_schema.columns 
        WHERE table_schema = 'data_center_new' 
        AND table_name = 'basic_monitoring_asset' 
        AND column_name = 'user_manual'
    ) THEN
        ALTER TABLE basic_monitoring_asset 
        ADD COLUMN `user_manual` text COMMENT '用户手册存放地址';
    END IF;
    
    IF NOT EXISTS (
        SELECT * 
        FROM information_schema.columns 
        WHERE table_schema = 'data_center_new' 
        AND table_name = 'basic_monitoring_asset' 
        AND column_name = 'device_image'
    ) THEN
        ALTER TABLE basic_monitoring_asset 
        ADD COLUMN `device_image` text COMMENT '设备图片存放地址';
    END IF;
    
    IF NOT EXISTS (
        SELECT * 
        FROM information_schema.columns 
        WHERE table_schema = 'data_center_new' 
        AND table_name = 'type' 
        AND column_name = 'device_category_id'
    ) THEN
        ALTER TABLE `type` 
        ADD COLUMN `device_category_id` bigint DEFAULT NULL COMMENT '设备大类ID';
    END IF;
    
    IF NOT EXISTS (
        SELECT * 
        FROM information_schema.columns 
        WHERE table_schema = 'data_center_new' 
        AND table_name = 'type' 
        AND column_name = 'unit'
    ) THEN
        ALTER TABLE `type` 
        ADD COLUMN `unit` varchar(255) DEFAULT NULL COMMENT '单位信息';
    END IF;
    
END$$

DELIMITER ;


CALL add_column();

DROP procedure IF EXISTS `add_column`;