import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddFeishuBotKnowledgeFields1773200000000 implements MigrationInterface {
  name = 'AddFeishuBotKnowledgeFields1773200000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    // 添加知识库ID字段
    await queryRunner.query(`
            ALTER TABLE feishu_bots 
            ADD COLUMN knowledge_base_id VARCHAR(36) NULL;
        `);

    // 添加知识组ID字段
    await queryRunner.query(`
            ALTER TABLE feishu_bots 
            ADD COLUMN knowledge_group_id VARCHAR(36) NULL;
        `);

    // 添加外键约束（可选，如果需要引用完整性）
    // 注意：这里假设 knowledge_bases 和 knowledge_groups 表存在
    // 如果表不存在，可以先创建或移除外键约束
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
            ALTER TABLE feishu_bots 
            DROP COLUMN knowledge_base_id;
        `);

    await queryRunner.query(`
            ALTER TABLE feishu_bots 
            DROP COLUMN knowledge_group_id;
        `);
  }
}
