SET @db = DATABASE();

SET @table = 'gxmu_work_ledger';

SET @sql = IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = @db AND TABLE_NAME = @table AND COLUMN_NAME = 'branch_secretary_name'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN branch_secretary_name VARCHAR(100) NULL COMMENT ''团支部书记姓名'' AFTER smart_league_entry_rate');
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 = @table AND COLUMN_NAME = 'branch_secretary_phone'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN branch_secretary_phone VARCHAR(50) NULL COMMENT ''团支部书记手机号'' AFTER branch_secretary_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 = @table AND COLUMN_NAME = 'total_people_count'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN total_people_count VARCHAR(50) NULL COMMENT ''总人数'' AFTER branch_secretary_phone');
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 = @table AND COLUMN_NAME = 'party_member_count'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN party_member_count VARCHAR(50) NULL COMMENT ''党员数'' AFTER total_people_count');
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 = @table AND COLUMN_NAME = 'youth_count'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN youth_count VARCHAR(50) NULL COMMENT ''青年数'' AFTER party_member_count');
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 = @table AND COLUMN_NAME = 'league_youth_ratio'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN league_youth_ratio VARCHAR(100) NULL COMMENT ''团青比例'' AFTER youth_count');
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 = @table AND COLUMN_NAME = 'branch_annual_summary'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN branch_annual_summary LONGTEXT NULL COMMENT ''团支部年度工作总结'' AFTER league_youth_ratio');
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 = @table AND COLUMN_NAME = 'standard_level'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN standard_level VARCHAR(100) NULL COMMENT ''对标定级等次'' AFTER branch_annual_summary');
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 = @table AND COLUMN_NAME = 'branch_committee_members'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN branch_committee_members LONGTEXT NULL COMMENT ''团支部班子成员名单(JSON)'' AFTER branch_annual_summary');
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 = @table AND COLUMN_NAME = 'league_member_registers'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN league_member_registers LONGTEXT NULL COMMENT ''团员登记(JSON)'' AFTER branch_committee_members');
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 = @table AND COLUMN_NAME = 'youth_registers'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN youth_registers LONGTEXT NULL COMMENT ''青年登记(JSON)'' AFTER league_member_registers');
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 = @table AND COLUMN_NAME = 'branch_honor_records'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN branch_honor_records LONGTEXT NULL COMMENT ''团支部荣誉登记(JSON)'' AFTER youth_registers');
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 = @table AND COLUMN_NAME = 'member_fee_records'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN member_fee_records LONGTEXT NULL COMMENT ''团员团费收缴登记(JSON)'' AFTER branch_honor_records');
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 = @table AND COLUMN_NAME = 'branch_meeting_records'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN branch_meeting_records LONGTEXT NULL COMMENT ''团支部会议记录(JSON)'' AFTER member_fee_records');
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 = @table AND COLUMN_NAME = 'branch_activity_records'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN branch_activity_records LONGTEXT NULL COMMENT ''团支部活动记录(JSON)'' AFTER branch_meeting_records');
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 = @table AND COLUMN_NAME = 'branch_education_evaluations'), 'SELECT 1', 'ALTER TABLE gxmu_work_ledger ADD COLUMN branch_education_evaluations LONGTEXT NULL COMMENT ''团支部教育评议结果(JSON)'' AFTER branch_activity_records');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
