const { PrismaClient } = require('@prisma/client'); const p = new PrismaClient(); async function ensureColumn(table, column, ddl) { const cols = await p.$queryRawUnsafe(`SHOW COLUMNS FROM \`${table}\` LIKE '${column}'`); if (!cols.length) { await p.$executeRawUnsafe(ddl); console.log(`added ${table}.${column}`); } else { console.log(`${table}.${column} exists`); } } (async () => { await ensureColumn( 'wecom_bot', 'ai_enabled', 'ALTER TABLE `wecom_bot` ADD COLUMN `ai_enabled` TINYINT(1) NOT NULL DEFAULT 0 AFTER `permissions`', ); await ensureColumn( 'wecom_bot', 'llm_config_id', 'ALTER TABLE `wecom_bot` ADD COLUMN `llm_config_id` BIGINT UNSIGNED NULL AFTER `ai_enabled`', ); await ensureColumn( 'wecom_bot', 'knowledge_base_id', 'ALTER TABLE `wecom_bot` ADD COLUMN `knowledge_base_id` BIGINT UNSIGNED NULL AFTER `llm_config_id`', ); await p.$disconnect(); })().catch(async (e) => { console.error(e); await p.$disconnect(); process.exit(1); });