SET @db = DATABASE();

SET @sql = IF(
    EXISTS(
        SELECT 1 FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'gxmu_tygl_form' AND COLUMN_NAME = 'college'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_tygl_form ADD COLUMN college VARCHAR(255) NULL COMMENT ''学院'' AFTER nation'
);
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_tygl_form' AND COLUMN_NAME = 'class_name'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_tygl_form ADD COLUMN class_name VARCHAR(255) NULL COMMENT ''班级'' AFTER college'
);
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_tygl_form' AND COLUMN_NAME = 'politics'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_tygl_form ADD COLUMN politics VARCHAR(100) NULL COMMENT ''政治面貌'' AFTER class_name'
);
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_tygl_form' AND COLUMN_NAME = 'branch_organization_id'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_tygl_form ADD COLUMN branch_organization_id INT NULL COMMENT ''所属团支部ID'' AFTER league_position'
);
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_tygl_form' AND COLUMN_NAME = 'branch_organization_name'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_tygl_form ADD COLUMN branch_organization_name VARCHAR(255) NULL COMMENT ''所属团支部'' AFTER branch_organization_id'
);
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_tygl_form' AND COLUMN_NAME = 'id_card_no'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_tygl_form ADD COLUMN id_card_no VARCHAR(32) NULL COMMENT ''身份证号'' AFTER branch_organization_name'
);
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_tygl_form' AND COLUMN_NAME = 'birth_date'
    ),
    'SELECT 1',
    'ALTER TABLE gxmu_tygl_form ADD COLUMN birth_date VARCHAR(20) NULL COMMENT ''出生日期'' AFTER id_card_no'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
