-- ============================================================================
-- 龙虾引擎模型升级补丁
-- 修复: P0 canvasData缺失, P0 Task字段缺失, P2 NodeExecutionLog缺失列
-- 日期: 2026-06-05
-- ============================================================================

-- 1. lobster_node_execution_log 增加 node_code 和 quality_score 列
ALTER TABLE `lobster_node_execution_log`
    ADD COLUMN `node_code` varchar(100) DEFAULT NULL COMMENT '节点编码' AFTER `workflow_id`,
    ADD COLUMN `quality_score` int DEFAULT NULL COMMENT '质量评分(0-100)' AFTER `retry_count`;

-- 2. company_workflow_lobster_task 增加 external_user_id 列（如尚未存在）
ALTER TABLE `company_workflow_lobster_task`
    ADD COLUMN IF NOT EXISTS `external_user_id` varchar(255) DEFAULT NULL COMMENT '外部联系人ID' AFTER `binding_id`;

-- 3. 为 lobster_node_execution_log 增加按节点统计的索引
CREATE INDEX IF NOT EXISTS `idx_exec_log_company_node` ON `lobster_node_execution_log` (`company_id`, `node_code`);
