-- 为tb_resource表添加知识库相关字段
-- 执行前请确认数据库连接正确

USE school_news;

-- 添加知识库相关字段
ALTER TABLE `tb_resource` 
ADD COLUMN `is_in_knowledge` TINYINT(1) DEFAULT 0 COMMENT '是否已导入知识库' AFTER `is_banner`,
ADD COLUMN `knowledge_file_id` VARCHAR(50) DEFAULT NULL COMMENT '知识库文件ID' AFTER `is_in_knowledge`,
ADD COLUMN `knowledge_import_time` TIMESTAMP NULL DEFAULT NULL COMMENT '知识库导入时间' AFTER `knowledge_file_id`;

-- 添加索引
ALTER TABLE `tb_resource` ADD INDEX `idx_is_in_knowledge` (`is_in_knowledge`);

-- 验证字段添加成功
SELECT COLUMN_NAME, COLUMN_TYPE, COLUMN_COMMENT 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = 'school_news' 
AND TABLE_NAME = 'tb_resource' 
AND COLUMN_NAME IN ('is_in_knowledge', 'knowledge_file_id', 'knowledge_import_time');
