SET @db = DATABASE();

SET @sql = IF(
    EXISTS(
        SELECT 1 FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'gxmu_declare' AND COLUMN_NAME = 'form_project_type'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_declare ADD COLUMN form_project_type TEXT NULL COMMENT ''挑战杯项目申报表项目类型(JSON数组字符串)'' AFTER project_group'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql = IF(
    EXISTS(
        SELECT 1 FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'gxmu_declare' AND COLUMN_NAME = 'form_project_group'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_declare ADD COLUMN form_project_group TEXT NULL COMMENT ''挑战杯项目申报表项目分组(JSON数组字符串)'' AFTER form_project_type'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql = IF(
    EXISTS(
        SELECT 1 FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'gxmu_declare' AND COLUMN_NAME = 'public_project_type'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_declare ADD COLUMN public_project_type TEXT NULL COMMENT ''挑战杯公开展示信息表项目类型(JSON数组字符串)'' AFTER form_project_group'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql = IF(
    EXISTS(
        SELECT 1 FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'gxmu_declare' AND COLUMN_NAME = 'public_project_group'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_declare ADD COLUMN public_project_group TEXT NULL COMMENT ''挑战杯公开展示信息表项目分组(JSON数组字符串)'' AFTER public_project_type'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

UPDATE gxmu_declare
SET
    form_project_type = COALESCE(form_project_type, project_type),
    form_project_group = COALESCE(form_project_group, project_group),
    public_project_type = COALESCE(public_project_type, project_type),
    public_project_group = COALESCE(public_project_group, project_group)
WHERE module = 'gxmu_tzbcy_form';

SET @sql = IF(
    EXISTS(
        SELECT 1 FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'gxmu_tzbcy_form' AND COLUMN_NAME = 'public_project_type'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_tzbcy_form ADD COLUMN public_project_type VARCHAR(64) NULL COMMENT ''公开展示项目类型'' AFTER project_group'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @sql = IF(
    EXISTS(
        SELECT 1 FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'gxmu_tzbcy_form' AND COLUMN_NAME = 'public_project_group'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_tzbcy_form ADD COLUMN public_project_group VARCHAR(128) NULL COMMENT ''公开展示项目分组'' AFTER public_project_type'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

UPDATE gxmu_tzbcy_form
SET
    public_project_type = COALESCE(public_project_type, project_type),
    public_project_group = COALESCE(public_project_group, project_group);
